JComboBox 宽度
2022-09-03 04:32:29
我创建了一个jComboBox,但它需要框架的整个宽度。如何设置固定宽度。
yes 框架的边框布局和面板的框布局。我在这里添加代码:
import javax.swing.*;
import java.awt.BorderLayout;
public class Window8 {
JFrame frame;
JPanel panel;
JComboBox combo;
public void go(){
String[] option = { "STUDENT", "TEACHER" };
combo.setPreferredSize(new Dimension(1,25));
combo = new JComboBox(option);
menu.setSelectedIndex(0);
frame = new JFrame("DELETION");
frame.setLocationRelativeTo(null);
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
panel = new JPanel();
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
frame.getContentPane().add(BorderLayout.NORTH,panel);
panel.add(combo);
}