开发者

Java (swing): Annoyance resizing JFrame by dragging the bottom left corner

Java (swing): Annoyance resizing JFrame by dragging the bottom left corner

The black is JFrame c开发者_开发百科ontent and the red one is JPanel's. This happens a lot when resizing the JFrame. A little less, when resizing the frame from upper left corner, but still happens. The panel is not able to keep up with the frame change.

Why, is it "fixable" ?

Thanks


The following lines provide the desired behavior on a JFrame:

public class MyFrame extends JFrame {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                new MyFrame().setVisible(true);
            }
        });
    }

    public MyFrame() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        setBackground(Color.black);

        JPanel panel = new JPanel();
        panel.setBackground(Color.red);

        getContentPane().add(panel);

        pack();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜