Set a Title for a jPanel on eclipse

13,767

This is What I did

JPanel mainPanel = new JPanel();

String title = "A titled border";
Border border = BorderFactory.createTitledBorder(title);
mainPanel.setBorder(border);
Share:
13,767
Beginnerprogrammer
Author by

Beginnerprogrammer

Updated on July 14, 2022

Comments

  • Beginnerprogrammer
    Beginnerprogrammer almost 2 years

    I'm new to programming and I have a question about the window builder. I searched online looking for a way to set a title for a jPanel and not a Jframe, and all what I found was to use for the Jframe setVisible. I don't know if there is a way to set a title for jpanel. I need the user to always see which screen he accessed. I'm using eclipse java language. Please help

  • byxor
    byxor over 7 years
    I've tweaked your code a little bit to make it more readable.
  • Beginnerprogrammer
    Beginnerprogrammer over 7 years
    Thank you ! @BrandonIbbotson
  • Gustavo Rodríguez
    Gustavo Rodríguez over 4 years
    I got "error: cannot find symbol" around "Border" so I must add "import javax.swing.border.TitledBorder;" and replace "Border border" by "TitledBorder border= BorderFactory.createTitledBorder("A titled border");"