• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Volodymyr Lysenko
Ranch Hand
Posts: 512
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!
 
Campbell Ritchie
Marshal
Posts: 52549
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell us full details, only thuscan we help.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • 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:

 
Volodymyr Lysenko
Ranch Hand
Posts: 512
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
Ranch Hand
Posts: 2699
10
  • 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.
 
Darryl Burke
Bartender
Posts: 5153
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.
 
Volodymyr Lysenko
Ranch Hand
Posts: 512
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: 5153
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!