[問題] JTextField 固定大小
最近剛開始在學 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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):