我试图将组件添加到JPanel,然后将该面板放入JScrollPane,然后将JScrollPane放入JOptionPane。问题:仅添加了19行组件。有一个用于确定组件行数的for循环,如果将条件计数器更改为19或更少,则将显示所有组件。这是问题的SSCCEimport java.awt.Dimension;import javax.swing.GroupLayout;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.SwingConstants;public class DynamicGroupLayout extends JPanel{ JButton addRecordButton; JTextField[] FieldsArray; JLabel[] LabelsArray; GroupLayout layout; JScrollPane scrollPane; public DynamicGroupLayout() { addRecordButton = new JButton("add record"); layout = new GroupLayout(this); this.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); scrollPane = new JScrollPane(this); scrollPane.getVerticalScrollBar().setUnitIncrement(16); scrollPane.setPreferredSize(this.getPreferredSize()); setTextFields(); showDialog(); } @Override public Dimension getPreferredSize() { return new Dimension(400, 500); } private void setTextFields() { int num = 30; //If 19 or less, all components shown. String[] labelsNames = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30" };
添加回答
举报
0/150
提交
取消