JPanel标题边框中的问题

时间:2015-07-03 04:44:16

标签: java swing

我在面板中有textArea。当我向面板添加一个线条边框时,它完全围绕着textarea。但是当我向面板添加标题边框时,textarea中的某些文本在可见区域中丢失了。我认为这里有一些插入问题。有人可以帮助将插图设置为标题边框吗?

发布我的layoutcomponents代码:

setPreferredSize(new java.awt.Dimension(250, 40));
add(summaryTextField);
Border border = (BorderFactory.createLineBorder(Color.red));
setBorder(BorderFactory.createTitledBorder(border,"Details"));

1 个答案:

答案 0 :(得分:0)

嗨,当我将gridbaglayout添加到面板时,它有效。

 setPreferredSize(new java.awt.Dimension(250, 50));
setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridheight = 1;
    constraints.gridwidth = 1;
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.LINE_START;
    constraints.insets = new Insets(0, 5, 5, 0);
    add(summaryTextField, constraints);
    setBorder(BorderFactory.createTitledBorder("Details"));

请参阅http://www.coderanch.com/t/333380/GUI/java/Adjust-border-margins-size-JPanel