JComboBox 第一次后不显示下拉箭头 运行
JComboBox Not Showing Drop-Down Arrow After First Time Running
我已经尝试了很多关于 google 的帮助,但我找不到任何与我的 problem.I 相关的东西,我面临着严重的 problem.I 我在我的 java 程序它只在我第一次 运行 程序时显示,但在第一次之后它不显示下拉列表 arrow.I 没有使用任何 removeAll();或任何类型的 remove();方法。
任何帮助将不胜感激,因为我看到很多人都遇到同样的问题。`class GPACalculator{
JFrame框架;
J标签选择;
JComboBox 子;
字体f1;
JTextField nameText;
J按钮输入;
public GPACalculator() {
frame = new JFrame("GPA Calculator---COMSATS Institute of Information Technology");
frame.setSize(720, 640);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon head = new ImageIcon("images/Header.jpg");
JLabel header = new JLabel(head);
header.setSize(720,90);
header.setLocation(0, 0);
ImageIcon log = new ImageIcon("images/Logo.png");
JLabel logo = new JLabel(log);
logo.setSize(300,300);
logo.setLocation(480, 400);
selection = new JLabel("Select Number Of Subjects And Press Enter");
f1 = new Font("Gabriola",Font.BOLD,30);
selection.setFont(f1);
selection.setLocation(10, 150);
selection.setSize(800, 50);
String[] subject = {"1","2","3","4","5"};
sub = new JComboBox<String>(subject);
sub.setBounds(10, 200, 300, 50);
Container c = frame.getContentPane();
c.setLayout(null);
c.setBackground(new Color(176,196,222));
c.add(header,BorderLayout.CENTER);
c.add(logo);
c.add(selection);
c.add(sub);
}
public static void main(String[] args){
new GPACalculator();
}
}
`
这是你的问题:
c.setLayout(null);
避免使用空布局,而是使用适当的布局管理器,您的代码可能会运行良好。
我已经尝试了很多关于 google 的帮助,但我找不到任何与我的 problem.I 相关的东西,我面临着严重的 problem.I 我在我的 java 程序它只在我第一次 运行 程序时显示,但在第一次之后它不显示下拉列表 arrow.I 没有使用任何 removeAll();或任何类型的 remove();方法。 任何帮助将不胜感激,因为我看到很多人都遇到同样的问题。`class GPACalculator{ JFrame框架; J标签选择; JComboBox 子; 字体f1; JTextField nameText; J按钮输入;
public GPACalculator() {
frame = new JFrame("GPA Calculator---COMSATS Institute of Information Technology");
frame.setSize(720, 640);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon head = new ImageIcon("images/Header.jpg");
JLabel header = new JLabel(head);
header.setSize(720,90);
header.setLocation(0, 0);
ImageIcon log = new ImageIcon("images/Logo.png");
JLabel logo = new JLabel(log);
logo.setSize(300,300);
logo.setLocation(480, 400);
selection = new JLabel("Select Number Of Subjects And Press Enter");
f1 = new Font("Gabriola",Font.BOLD,30);
selection.setFont(f1);
selection.setLocation(10, 150);
selection.setSize(800, 50);
String[] subject = {"1","2","3","4","5"};
sub = new JComboBox<String>(subject);
sub.setBounds(10, 200, 300, 50);
Container c = frame.getContentPane();
c.setLayout(null);
c.setBackground(new Color(176,196,222));
c.add(header,BorderLayout.CENTER);
c.add(logo);
c.add(selection);
c.add(sub);
}
public static void main(String[] args){
new GPACalculator();
}
} `
这是你的问题:
c.setLayout(null);
避免使用空布局,而是使用适当的布局管理器,您的代码可能会运行良好。