How to add support for resizing when using an undecorated JFrame?
Posted
by Jonas
on Stack Overflow
See other posts from Stack Overflow
or by Jonas
Published on 2010-05-06T11:47:13Z
Indexed on
2010/05/06
11:58 UTC
Read the original article
Hit count: 189
I would like to customize my titlebar, minimize-, maximize- and the close-button. So I used setUndecorated(true);
on my JFrame, but I still want to be able to resize the window. What is the best way to implement that?
I have a border on the RootPane, and I could use MouseListeners on the Border or the RootPane. Any recommendations?
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.border.LineBorder;
public class UndecoratedFrame extends JFrame {
private LineBorder border = new LineBorder(Color.BLUE,2);
private JMenuBar menuBar = new JMenuBar();
private JMenu menu = new JMenu("File");
private JMenuItem item = new JMenuItem("Nothing");
public UndecoratedFrame() {
menu.add(item);
menuBar.add(menu);
this.setJMenuBar(menuBar);
this.setUndecorated(true);
this.getRootPane().setBorder(border);
this.setSize(400,340);
this.setVisible(true);
}
public static void main(String[] args) {
new UndecoratedFrame();
}
}
© Stack Overflow or respective owner