• Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 58823
179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell us full details, only thuscan we help.
 
Rancher
Posts: 2891
17
  • 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: 2891
17
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!