所以我的问题是,我以前在 Jspinners 上遇到过。是我用带标题的边框包围我的 jspinner。然而,在 gui 中,它削减了标题文本,因为 js 更小。那么如何根据标题的长度强制 gui 重新调整,或者如何让 jspinner 更长,我想提供足够的空间来容纳整个标题?
JTextField name= new JTextField(9);
name.setBorder(new TitledBorder("Name"));
//setup spinner date format
SimpleDateFormat datePattern = new SimpleDateFormat("MM/dd/yyyy");
JSpinner dob = new JSpinner(new SpinnerDateModel());
dob.setEditor(new JSpinner.DateEditor(dob, datePattern.toPattern()));
dob.setBorder(new TitledBorder("Date of Birth"));
JPanel childPanel = new JPanel();
childPanel.setLayout(new FlowLayout());
childPanel.add(name);
childPanel.add(dob);
childPanel.setBorder(new TitledBorder("Child Info"));
然后:
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
mainPanel.add(childPanel);
childPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
//there are more items in this panel, just omitted them, that's why using BoxLayout