[英]JPanel - GridLayout
我目前创建了GridLayout:它有4列,前两列是进度条,另外两列是开始/停止按钮。 如何将最后两个按钮放在彼此旁边?
我多么想要:
进度条
进度条
开始停止
怎么样:
进度条
进度条
开始
停
即使我将布局更改为:panel.setLayout(new GridLayout(3,2,3,3)); 它不起作用,任何人都可以帮助我吗?
只需将两个JProgressBar
JPanel say centerPanel
带有BridLayout(0, 1, 5, 5)
JPanel say centerPanel
的JPanel say centerPanel
BridLayout(0, 1, 5, 5)
。
并将2 JButton
的START and STOP
放到另一个JPanel say buttonPanel
,即布局,即FlowLayout(FlowLayout.LEFT, 5, 5)
(这将使JButton
START与JProgressBar
的左侧对齐,但是如果你想要JButton
的话来到同一个地方的某个地方,然后根本就不要使用 。 setLayout(FlowLayout.LEFT, 5, 5)
JPanel
的默认布局可以)。
现在使用将centerPanel
添加到JFrame
frameReference.add(centerPanel, BorderLayout.CENTER)
并使用添加buttonPanel
frameReference.add(buttonPanel, BorderLayout.PAGE_END)
那样做:-)
为这件东西使用Border
。 喜欢
centerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK))
这将在centerPanel
周围创建一个Box
。 请看一下这个答案 ,虽然我在这个例子中使用的是TitledBorder
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.