简体   繁体   English

JPanel的标题边框问题

[英]Issue in Title Border of a JPanel

I have textArea inside panel. 我在面板内有textArea。 When I add a line border to panel, it is coming perfectly around textarea. 当我在面板上添加线条边框时,它恰好在textarea周围。 But when I add titled border to panel some of the text in textarea is missing from the visible area. 但是,当我在面板上添加标题边框时,可见区域中缺少textarea中的某些文本。 I think there is some inset issue here. 我认为这里存在一些插图问题。 Can someone please help in setting the insets to titled border? 有人可以帮忙将插图设置为标题边框吗?

Posting my code of layoutcomponents: 发布我的layoutcomponents代码:

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

Hi it worked when I added gridbaglayout to panel. 嗨,当我向面板添加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"));

Please refer to http://www.coderanch.com/t/333380/GUI/java/Adjust-border-margins-size-JPanel 请参考http://www.coderanch.com/t/333380/GUI/java/Adjust-border-margins-size-JPanel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM