简体   繁体   中英

Issue in Title Border of a JPanel

I have textArea inside panel. When I add a line border to panel, it is coming perfectly around textarea. But when I add titled border to panel some of the text in textarea is missing from the visible area. I think there is some inset issue here. Can someone please help in setting the insets to titled border?

Posting my code of 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.

 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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