public void start_Gui() {
JFrame window = new JFrame("Client Program");
window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
window.setContentPane(panel);
panel.setLayout(new GridLayout(1,2));
JLabel leftside = new JLabel();
leftside.setLayout(new GridLayout(2, 1));
JTextArea rightside = new JTextArea();
rightside.setEditable(false); //add scroll pane.
rightside.setBorder(BorderFactory.createLineBorder(Color.BLACK));
rightside.setLayout(new FlowLayout());
JTextArea client_text_input = new JTextArea();
client_text_input.setBorder(BorderFactory.createLineBorder(Color.BLACK));
leftside.add(client_text_input);
JLabel buttons_layer = new JLabel();
JButton login = new JButton("Login");
JButton logout = new JButton("Logout");
buttons_layer.setBorder(BorderFactory.createLineBorder(Color.BLACK));
buttons_layer.setLayout(new GridLayout(2, 1));
buttons_layer.add(login);
buttons_layer.add(logout);
leftside.add(buttons_layer);
panel.add(leftside);
panel.add(rightside);
window.setSize(300, 400);
window.setResizable(false);
window.setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)
我正在研究一个简单的Java聊天客户端gui应用程序.(服务器等,由其他人完成).
这不是一个大项目,但我唯一的问题是,无论我尝试调整上述GUI上的任何组件的大小,都行不通.
例如:
JTextArea client_text_input = new JTextArea();
client_text_input.setSize(100,200);
Run Code Online (Sandbox Code Playgroud)
不行.
谢谢您的帮助.
Joa*_*uer 20
在Swing中,您有两种布局选项:手动完成所有操作或让LayoutManager您为其处理.
通话setSize()仅在您不使用时才有效LayoutManager.由于您正在使用a,因此GridLayout您必须使用其他方式来指定您想要的内容.
试着打电话setPreferredSize()和setMinimumSize().
| 归档时间: |
|
| 查看次数: |
15911 次 |
| 最近记录: |