【发布时间】:2024-01-11 09:03:01
【问题描述】:
我有 2 个 JPanel、1 个按钮面板和一个图形面板。我希望按钮面板位于图形面板的正下方,但按钮面板切断了中间的图形面板。我一直在尝试从讨论中看到的盒子布局似乎是我想做的最好的格式。谁能给我一些关于我的格式问题的建议。
JFrame canvas = new JFrame("Baseball Strike K");
JFrame canvas = new JFrame ("GraphicBoard");
canvas.setVisible(true);
canvas.setSize(1000,1000);
canvas.setDefaultCloseOperation(EXIT_ON_CLOSE);
//create two panels
//add them to contentPane
//set Layout
JPanel buttonPanel = createButtons();
JPanel mainPanel = new Graphic(); //extends JPanel and writes the paint method
mainPanel.setSize(1000, 1000);
Container content = canvas.getContentPane();
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
content.add(mainPanel);
content.add(buttonPanel);
【问题讨论】:
-
没有足够的代码。至少需要看到 Graphic 和 createButtons。一个可运行的示例也会非常有用
-
看看 Eclipse IDE 中的 WindowBuilder。你不会回头。
-
1) 为了尽快获得更好的帮助,请发帖 SSCCE。 2) 见The Use of Multiple JFrames, Good/Bad Practice? 3)
extends JPanel and writes the paint method应该是..the paintComponent method
标签: java swing jframe jpanel layout-manager