• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setBorder --> titleBorder

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anything guys?
Content minimized. Click to view
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic