• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to set background color of javax.swing.Box in swing?  RSS feed

 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

How to set background color of javax.swing.Box in swing?
My code does not work:

Thank you!
 
Marshal
Posts: 61761
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell us full details, only thuscan we help.
 
Rancher
Posts: 2974
20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Box is just meant to be a container to hold other components, so by default it is transparent. You need to make it opaque:

 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replies!

Can you also tell me why are my components(JButton) are placed centrally within this horizontal toolbarBox?
I mean components do not want to lay from left to right but they are laid out on the center of Box.

Thanks!
 
Rob Camick
Rancher
Posts: 2974
20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can you also tell me why are my components(JButton) are placed centrally within this horizontal toolbarBox?



Who knows. Your create a Box, add it to a JPanel, and then somewhere else you add the panel to the frame.

We don't know what layout managers you are using at the different levels.

If you need help then post a proper SSCCE in another question.
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Volodymyr Levytskyi wrote:


I could be wrong, but I think it's time for you to learn about JToolBar.
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I do not know much of jtoolbar and Box is suitable here.

To have components in Box laid out from right to left you need :

Now the first added component is on the right of Box.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Volodymyr Levytskyi wrote:No, I do not know much of jtoolbar


What I said.

Darryl Burke wrote:I could be wrong, but I think it's time for you to learn about JToolBar.


Or reinvent the wheel.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!