0 java layout user-interface swing layout-manager
我现在已经在这一段时间了,但我似乎无法掌握它.我正在尝试生成一个JPanel,上面有一个JTextArea,下面有两个JLabel,但我的JLabel最终位于我的JTextArea的左侧,我不能让另一个出现.
这是我的代码(抱歉显示的东西 - 只是填充物真的):
public JPanel contentPane() {
JPanel something = new JPanel();
String information = "Please";
info = new JTextArea(information, 4, 30);
info.setEditable(false);
info.setLineWrap(true);
info.setWrapStyleWord(true);
JPanel one = new JPanel(new BorderLayout());
one.setBackground(Color.WHITE);
one.setLocation(10, 10);
one.setSize(50, 50);
one.add(info, BorderLayout.CENTER);
something.add(one, BorderLayout.NORTH);
JPanel two = new JPanel(new BorderLayout());
two.setBackground(null);
two.setLocation(220, 10);
two.setSize(50, 50);
two.add(new JLabel("Please work"), BorderLayout.EAST);
two.add(new JLabel("Oh gosh, please"), BorderLayout.WEST);
something.add(two, BorderLayout.SOUTH);
something.setOpaque(true);
return something;
}
public static void GUI() {
JFrame frame = new JFrame("You Guessed It!");
DisplayStudent panel = new DisplayStudent();
frame.setContentPane(panel.contentPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 150);
frame.setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)
对于花时间提供帮助的人,请多谢.
当你创建你的东西,你不指定任何布局管理器,但后来你尝试添加一个到的东西用BorderLayout的常数-这是行不通的,因为对于一个JPanel的默认布局管理器是FlowLayout中.
试试这个;
JPanel something = new JPanel(new BorderLayout());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
105 次 |
| 最近记录: |