我已经为此工作了一段时间,但终其一生却一事无成。我正在尝试将按钮和标签设置为彼此重叠而不是并排设置。我想我必须将布局从 FlowLayout 更改为 BoxLayout 但我不知道该怎么做。这就是我到目前为止所拥有的。
import javax.swing.JFrame;
public class VoteCounter
{
//----------------------------------------------
// Creates the main program frame.
//----------------------------------------------
public static void main(String[] args)
{
JFrame frame = new JFrame("Vote Counter");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new VoteCounterPanel());
frame.pack();
frame.setVisible(true);
}
}
任何帮助将不胜感激。
最佳答案
frame.setLayout(new BoxLayout(frame, BoxLayout.PAGE_AXIS));
很简单。
更多信息请引用:http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html
关于java - 如何在 JFrame 中将 FlowLayout 更改为 BoxLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28068884/