• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to have 2 JTabspanes on the same screen with 2 different Active Tab colors; UIManager  RSS feed

 
Peter Lock
Greenhorn
Posts: 24
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First Time Member: Code Ranch

Hi Everyone, I joined CodeRanch yesterday. I hope this is the right place to post this.

How can we change the color of the active tabs on JTabbedpanes; with two JTabbedpanes being displayed one below the other. I have been able to use the UIManager to this point to change the appearance, but cannot have two different colored Active tabs at the same time. If someone can please look at the code and tell me what I am doing wrong, with regards to having two different colors it would be greatly appreciated. Also I hope the code I have written, with the help of stack overflow, caveofprogramming, oracle docs, and others will benefit somebody else with similar problems. Right now the code displays two tabbed panes, one under the other, with a different looking UI and the same colored Active Tab (Light Green). I am trying to have a light green Active tab for the top JTabbedPane, and a dark green Active tab for the bottom tab.

My question: How can we display two different active tabs on two different tabbedpanes by overriding the UI, or by any other means. I have been able to display the new UI for the top Tabpane, and the System UI with the bottom pane, but am unsure actually how everything fits. I have tried to find answers to this.

Kind regards

The code:




Any help with this would be grealty appreacted.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter, welcome to the Ranch!

That's a pretty good code sample you have there, nicely formatted. I googled a bit and found this antique post -- perhaps you saw it already, I see you're already using the technique it recommends to set your tab colour. However the first comment (although it's dated in 2002) might interest you as it suggests how you might use it to answer your question.

(Also I moved your post to the Swing/etc forum.)
 
Peter Lock
Greenhorn
Posts: 24
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul

Thank-you for reading my post. I had a read of the antique post you mentioned and will try to implement a switch statement to see if I cant get it to work. One idea I had was to turn on and off UI changes, but I dont know how to do that. If you or any other readers have any other ideas that could help I would be indebted.

Kind Regards
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things I noticed: the post I linked to says you're supposed to call UIManager.put("TabbedPane.selected" before creating a JTabbedPane which is supposed to be affected by that "put" call, but you do it afterwards. And second, you call UIManager.put("TabbedPane.selected" twice but with the same colour both times.
 
Peter Lock
Greenhorn
Posts: 24
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply - I moved the put UIManager.put("TabbedPane.selected" .. to before where I created the tabbedpanes to no affect. There are two greens, one slightly darker then the other. Through observation Ive noticed that when I remove the TabPaneUIManager.put .. the CustomerPane UIManager.put' takes affect for both tabPanes, and vice versa, both reflecting different shades of green, even though the customerPane object is created from the Tabpanes class. Again, thank-you for taking the time to help find a solution to this problem. Yesterday I was able to force the Customer pane back to the mac look and feel, while the TabPane class remained with its custom LF, but I could'nt add a new 'put' tothe CustomerPane again. If it would help would you like me to post the other few classes of code to see.

Regards
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No; showing more code wouldn't be helpful. What would be helpful would be to show LESS code. A lot of what you posted isn't really relevant to the problem, so you need to post an SSCCE (<-- follow that link) for a minimal example of the problem. If you can fix that, then the next step would be to incorporate the fix into your real code.
 
Peter Lock
Greenhorn
Posts: 24
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Thank-you for the link on providing a SSCCE. The problem is to have two tab-panes with different colored Active Tab. I think the problem is the the put statements are changing all UI for tabpanes in the JVM.

Either a new method/idea for changing the active state is needed or changing the UI for each instance of the jpane. Or I am completely wrong and dont know what I am talking about. Any help in solving this would be greatly appreciated. Using pane.updateUI(); at the end of the second tab pane class (customer) seems to reset the UI - I dont understand whats happening here yet and how to use this behaviour for a solution

The stripped down code:



Regards, and thank-you.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:

1. Remove the calls to super.installDefaults() in your UI inner classes.

2. Move the calls to UIManager.put so they're before the code which creates the JTabbedPane which they are supposed to affect.

Then I get something which seems to do what you want. Congrats on the competent SSCCE by the way.
 
Peter Lock
Greenhorn
Posts: 24
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

This has solved the problem. Thank you for all of your time and effort. I marked the post as helpful. To contribute to coderanch what should I also do to also help other members like you have helped me? Also do I know to close the post? Or should I leave it open for other members to view problem and answer. Again, thank you for your help. It was and is greatly appreciated.

Regards
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the interesting problem!

I've marked the post as "resolved", that means it stays visible and people can still post to it if they like but they can see that you think you have an answer.

To contribute to the Ranch: it seems like you're a pretty good Swing programmer so you could drop by the Swing forum from time to time and see if it has posts you can answer. Anybody's entitled to post on any thread (unless it's been locked by a moderator) and unlike most forums our first rule is "Be Nice".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!