作者CMturtle (杰尼龟)
看板java
标题[问题] JTextField 固定大小
时间Fri Aug 5 13:31:10 2011
最近刚开始在学 JAVA ,正在练习学写 GUI 介面
但是我的版面配置都不如我想要表现的状态
我的 JTextField 都会随着我的视窗大小变更长宽
介面就会变得不好看
有什麽方法可以改进吗?
我的code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GuiUserInterface
{
JFrame frame;
JPanel itemPanel;
JPanel choosePanel;
JPanel usernamePanel;
JPanel passwdPanel;
JPanel problemPanel;
JCheckBox uvaCheck;
JCheckBox pojCheck;
JLabel usernameLabel;
JTextField usernameField;
JLabel passwdLabel;
JPasswordField passwdField;
JLabel problemLabel;
JTextField problemField;
public static void main(String[] args)
{
new GuiUserInterface().go();
}
public void go()
{
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,220);
frame.setVisible(true);
itemPanel = new JPanel();
itemPanel.setLayout(new BoxLayout(itemPanel, BoxLayout.Y_AXIS));
choosePanel = new JPanel();
choosePanel.setLayout(new BoxLayout(choosePanel, BoxLayout.Y_AXIS));
uvaCheck = new JCheckBox("Submit to Uva");
pojCheck = new JCheckBox("Submit to POJ");
usernameLabel = new JLabel("Username: ");
usernameField = new JTextField(10);
passwdLabel = new JLabel("Password: ");
passwdField = new JPasswordField(10);
problemLabel = new JLabel("Problem ID: ");
problemField = new JTextField(10);
choosePanel.add(uvaCheck);
choosePanel.add(pojCheck);
choosePanel.add(usernameLabel);
choosePanel.add(usernameField);
choosePanel.add(passwdLabel);
choosePanel.add(passwdField);
choosePanel.add(problemLabel);
choosePanel.add(problemField);
itemPanel.add(choosePanel);
frame.getContentPane().add(BorderLayout.WEST, itemPanel);
frame.validate();
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.68.185