0

Looking at this example, I have to create a form look like: enter image description here

If you press the tab button, it will change the color of the background according to the color of the button.

Here is the code to do that:

private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {                                          
    getContentPane().setBackground(Color.YELLOW)
};

and this is the result:

enter image description here

My problem is: I can't set the color for the whole background, and I can't change the variable name of the tab, so I can't set different events with different colors for each tab. It says that two components in the same form cannot have the same name

Any help is appreciated.

Community
  • 1
  • 1
Wick
  • 51
  • 1
  • 8
  • I don't understand your question. What's wrong? Are all your tabs making the background yellow? – byxor Aug 29 '16 at 08:54
  • there are 2 problems: i can't the set whole the background color like the first image,somehow it only change a small area.Second is i can't set different color of each tab because everytime i try to make a new event for each tab,it always send me to jTabbedPane1MouseClicked – Wick Aug 29 '16 at 09:04
  • Problem 1: It looks like you're only setting the background colour for your JTabbedPane. --- Problem 2: I need to see more code before I can understand. Maybe post your entire JTabbedPane class (and everything else that's related)? – byxor Aug 29 '16 at 09:06
  • 1
    A complete example is shown [here](http://stackoverflow.com/a/8752166/230513). – trashgod Aug 29 '16 at 09:07

0 Answers0