use of javax.swing.event.MouseInputListener in project java-swing-tips by aterai.
the class CloseIcon method makeFrame.
public JFrame makeFrame(String str) {
JFrame frame = new JFrame(str) {
@Override
public Container getContentPane() {
return getMainContentPane();
}
};
frame.setUndecorated(true);
frame.setBackground(new Color(0x0, true));
JPanel title = new JPanel(new BorderLayout(W, W));
title.setOpaque(false);
title.setBackground(Color.ORANGE);
title.setBorder(BorderFactory.createEmptyBorder(W, W, W, W));
JCheckBox check = new JCheckBox("check");
check.setOpaque(false);
check.setFocusable(false);
Box titleBox = Box.createHorizontalBox();
titleBox.add(makeComboBox(str));
titleBox.add(Box.createHorizontalGlue());
titleBox.add(check);
JButton button = makeTitleButton(new ApplicationIcon());
button.addActionListener(e -> Toolkit.getDefaultToolkit().beep());
title.add(button, BorderLayout.WEST);
title.add(titleBox);
JButton close = makeTitleButton(new CloseIcon());
close.addActionListener(e -> {
JComponent b = (JComponent) e.getSource();
Container c = b.getTopLevelAncestor();
if (c instanceof Window) {
Window w = (Window) c;
w.dispatchEvent(new WindowEvent(w, WindowEvent.WINDOW_CLOSING));
}
});
title.add(close, BorderLayout.EAST);
MouseInputListener rwl = new ResizeWindowListener();
Stream.of(left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight).forEach(c -> {
c.addMouseListener(rwl);
c.addMouseMotionListener(rwl);
});
JPanel titlePanel = new JPanel(new BorderLayout());
titlePanel.add(top, BorderLayout.NORTH);
titlePanel.add(new JLayer<>(title, new TitleBarDragLayerUI()), BorderLayout.CENTER);
JPanel northPanel = new JPanel(new BorderLayout());
northPanel.add(topLeft, BorderLayout.WEST);
northPanel.add(titlePanel, BorderLayout.CENTER);
northPanel.add(topRight, BorderLayout.EAST);
JPanel southPanel = new JPanel(new BorderLayout());
southPanel.add(bottomLeft, BorderLayout.WEST);
southPanel.add(bottom, BorderLayout.CENTER);
southPanel.add(bottomRight, BorderLayout.EAST);
resizePanel.add(left, BorderLayout.WEST);
resizePanel.add(right, BorderLayout.EAST);
resizePanel.add(northPanel, BorderLayout.NORTH);
resizePanel.add(southPanel, BorderLayout.SOUTH);
resizePanel.add(contentPanel, BorderLayout.CENTER);
titlePanel.setOpaque(false);
northPanel.setOpaque(false);
southPanel.setOpaque(false);
contentPanel.setOpaque(false);
resizePanel.setOpaque(false);
frame.setContentPane(resizePanel);
return frame;
}
Aggregations