Code
//JFrame without close, minimize, maximize buttons.
final JInternalFrame internal = new JInternalFrame();
BasicInternalFrameUI ui = (BasicInternalFrameUI)internal.getUI();
Component title = ui.getNorthPane();
for(MouseMotionListener l:title.getListeners(MouseMotionListener.class)) {
title.removeMouseMotionListener(l);
}
DragWindowListener dwl = new DragWindowListener();
title.addMouseListener(dwl);
title.addMouseMotionListener(dwl);
JPanel p = new JPanel(new BorderLayout());
p.add(new JScrollPane(new JTree()));
p.add(new JButton(new AbstractAction("close") {
public void actionPerformed(ActionEvent e) {
Window w = SwingUtilities.windowForComponent((Component)e.getSource());
w.getToolkit().getSystemEventQueue().postEvent(
new WindowEvent(w, WindowEvent.WINDOW_CLOSING));
}
}), BorderLayout.SOUTH);
internal.getContentPane().add(p);
internal.setVisible(true);
KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
focusManager.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if("activeWindow".equals(prop)) {
try{
internal.setSelected(e.getNewValue()!=null);
}catch(PropertyVetoException ex) {
ex.printStackTrace();
}
}
}
References
No comments:
Post a Comment