• Post Reply Bookmark Topic Watch Topic
  • New Topic

setBorder --> titleBorder  RSS feed

 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I've got a question. I've got a frame and i've broken it up into 3 parts (each 1 JPanel) and i've placed them onto the frame. Now i've decided that I want a titleBorder around it. What is the best way to go about this?

Creating 1 panel instead of having 3? Can you have 1 panel and put that panel into another panel and set a title border?

Here is my code. When I run it the titleBorder comes off just to the right by default and I can't find an alternative to this

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. Nested panels are usually the best way to organize your visual controls.
Presuming you want one border around all 3 panels
1) Create a 'parent' panel.
2) Add the 3 'child' panels to the parent
3) Set the border to the parent
 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going home at the moment but tomorrow I'll give it a go and see how I go. I'll post the results here when I get a chance. Thanks for the quick reply!
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is bound to be something useful in the Java™ Tutorials.
 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmmm.... it seems that the title border is stuck in the middle of the panel and not surrounding the panel

 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try break down the logic here so you guys can let me know if it's right or wrong

i've got JComponents


and then i've got a JPanel that uses GridBagLayout



then I add the JComponents to the JPanel here



then the JPanel gets added to the JFrame



and lastly I create a titled border which I declare and then add to the JPanel



Can anyone see an issue with the logic behind this?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mitchell bat wrote:hmmmm.... it seems that the title border is stuck in the middle of the panel and not surrounding the panel

Well you DID set it to the center


I am not sure what you mean by "surrounding" the panel. Maybe a screenshot might help us understand
 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As requested here is the screenshot of what it looks like
Capture.JPG
[Thumbnail for Capture.JPG]
 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anything guys?
Content minimized. Click to view
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The screenshot you posted does not have any border titled "Title"
Are you sure the screenshot matches the code you are running?
 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah of course i'm sure, copy and paste it into your IDE and tell me what happens
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problems
1) frame.setLayout(new GridBagLayout());
You already set the layout for the mainPanel. Remove this

2) frame.add(username, constraints);
You are adding the components to the frame. They should be added to the mainPanel

Once you do, it should work out fine
Screen-Shot-2016-07-11-at-12.52.24-PM.png
[Thumbnail for Screen-Shot-2016-07-11-at-12.52.24-PM.png]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!