所以我的问题是,我之前在 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
最佳答案
只需将 JSpinner 添加到 JPanel,然后将边框添加到面板即可:
JPanel dobPanel = new JPanel();
dobPanel.add(dob);
dobPanel.setBorder(BorderFactory.createTitledBorder("Date of Birth"));
编辑:另请注意,使用 BorderFactory 比创建 Border 实例更好:
Wherever possible, this factory will hand out references to shared Border instances.
http://docs.oracle.com/javase/7/docs/api/javax/swing/BorderFactory.html
关于java - jspinner 标题边框被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10999453/