【发布时间】:2016-11-03 14:15:52
【问题描述】:
如何防止缩小只包含 JFormattedTextFields 的 JPanel。
JFormattedTextField textF1;
JFormattedTextField textF2;
textF1 = new JFormattedTextField(numberFormat);
textF2 = new JFormattedTextField(numberFormat);
JPanel labelPane = new JPanel(new GridLayout(0,1));
labelPane.add(textF1)
labelPane.add(textF2)
setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
add(labelPane, BorderLayout.LINE_START);
add(fieldPane, BorderLayout.CENTER);
add(imagePane, BorderLayout.LINE_END);
问题在于 fieldPane。它总是缩小。我试图将文本字段设置为最小尺寸,手动设置尺寸。甚至设置 prefferd 大小,setMaximumSize。不是这个作品。LabelPane 和 imagePane 工作正常。
【问题讨论】:
-
1) 为了尽快获得更好的帮助,请发帖 minimal reproducible example 或 Short, Self Contained, Correct Example。 2) 见Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?(是。) 3) 使用逻辑一致的缩进代码行和块的形式。缩进是为了让代码流更容易理解! 4) 尝试使用
setColumns(int)建议尺寸。
标签: java swing jpanel textfield