Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:35:59+00:00 2026-06-18T00:35:59+00:00

I created a JPanel and i have added a TitleBorder with BorderFactory but it’s

  • 0

I created a JPanel and i have added a TitleBorder with BorderFactory but it’s showing a blue line around the panel.
I would like to remove this line.

Any suggestions?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:36:01+00:00Added an answer on June 18, 2026 at 12:36 am
    • never tried to extract this value from TitleBorders API, methods are protected, or by using UIManager

    • have to use LineBorder inside TitleBorder

    • simpliest syntax could be xxx.setBorder(new TitledBorder(new LineBorder(Color.ORANGE, 1), "label")); or get the Color from (for example) myPanel.getBackground() instread of Color.ORANGE

    • another options are (is possible)

      1. move desciption (top, bottom…..)

      2. change Font

      3. change Foreground (Color for description)

    • more options and description in Oracle tutorial How to Use Borders (CompounBorders)

    for example

    enter image description here

    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.EventQueue;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.LineBorder;
    import javax.swing.border.TitledBorder;
    
    public class AddComponentsAtRuntime {
    
        private JFrame f;
        private JPanel panel;
        private JCheckBox checkValidate, checkReValidate, checkRepaint, checkPack;
    
        public AddComponentsAtRuntime() {
            JButton b = new JButton();
            b.setBackground(Color.red);
            b.setBorder(new LineBorder(Color.black, 2));
            b.setPreferredSize(new Dimension(600, 10));
            panel = new JPanel(new GridLayout(0, 1));
            panel.add(b);
            panel.setBorder(new TitledBorder(new LineBorder(Color.ORANGE, 1),
                    "Add Components At Runtime"));
            f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(panel, "Center");
            f.add(getCheckBoxPanel(), "South");
            f.setLocation(200, 200);
            f.pack();
            f.setVisible(true);
        }
    
        private JPanel getCheckBoxPanel() {
            checkValidate = new JCheckBox("validate");
            checkValidate.setSelected(false);
            checkReValidate = new JCheckBox("revalidate");
            checkReValidate.setSelected(false);
            checkRepaint = new JCheckBox("repaint");
            checkRepaint.setSelected(false);
            checkPack = new JCheckBox("pack");
            checkPack.setSelected(false);
            JButton addComp = new JButton("Add New One");
            addComp.addActionListener(new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    JButton b = new JButton();
                    b.setBackground(Color.red);
                    b.setBorder(new LineBorder(Color.black, 2));
                    b.setPreferredSize(new Dimension(600, 10));
                    panel.add(b);
                    makeChange();
                    System.out.println(" Components Count after Adds :" + panel.getComponentCount());
                }
            });
            JButton removeComp = new JButton("Remove One");
            removeComp.addActionListener(new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    int count = panel.getComponentCount();
                    if (count > 0) {
                        panel.remove(0);
                    }
                    makeChange();
                    System.out.println(" Components Count after Removes :" + panel.getComponentCount());
                }
            });
            JPanel panel2 = new JPanel();
            panel2.add(checkValidate);
            panel2.add(checkReValidate);
            panel2.add(checkRepaint);
            panel2.add(checkPack);
            panel2.add(addComp);
            panel2.add(removeComp);
            return panel2;
        }
    
        private void makeChange() {
            if (checkValidate.isSelected()) {
                panel.validate();
            }
            if (checkReValidate.isSelected()) {
                panel.revalidate();
            }
            if (checkRepaint.isSelected()) {
                panel.repaint();
            }
            if (checkPack.isSelected()) {
                f.pack();
            }
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    AddComponentsAtRuntime makingChanges = new AddComponentsAtRuntime();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

column header not visible in my JTable i have created a JPanel and added
I've created JPanel and have already added components into it and I'm going to
I have created jframe in which jpanels are added dynamically what i can't do
I have a program which creates JButtons which are then added to a JPanel
I have created a Hexagon component that extends JPanel . It draws a hexagon
I have added a JTextField to a JPanel using the Window Builder in Eclipse
I have made two panels and then added in third panel. How can I
I'm having a problem with this. I have a JPanel and normally I would
I have created a JDialog which contains a JComboBox and a panel underneath which
I have created some custom JPanel classes using the NetBeans GUI Builder. Next, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.