Updating a JTabbedPane's selected tab color dynamically

Hi
I have set the selected tab color for my JTabbedPane
using:
UIManager.put("TabbedPane.selected", Color.RED);Now I would like to change the color dynamically to green.
However, just calling:
UIManager.put("TabbedPane.selected", Color.GREEN);doesn't work.
It seems that if the JTabbedPane is visible while I change the color through the UIManager, it has no effect.
On the other hand, all the other JTabbedPanes in my application (which are not visible - in hidden dialogs), are effected.
How can I effect ALL the JTabbedPanes in my application at the same time?

Try to call
SwingUtilities.updateComponentTreeUI(selectedPane);
best regards
Stas

Similar Messages

  • JTabbedPane - BOLD selected tab title text.

    I want to BOLD the selected tab's title text while keeping the unselected tabs' title text in normal font. Anyone know how to achieve this effect?

    I think the simplest  way is to use JTabbedPane.setTabComponentAt, add your own labels, add a ChangeListener to the JTabbedPane and change the labels fonts when tab selection changes.

  • Change selected tab color theme

    I'm trying to make a small adjustment to my color theme. If you have used X-Chat Aqua, you'll notice that in the Blue OS X color theme, highlighted tabs are in blue, and easily identified. However, when the color scheme is grey, highlighted tabs are in a slightly darker grey, so I have to tilt my display back and forth to tell which tab is the active one. I prefer the grey theme, but want to change the highlighting color of the active tab. This does not have anything to do with the highlighting color in the OS X settings as I already have that set to turquoise. Does anyone know how to change this? Someone suggested Magnifique, but that seems like it will only install a whole new color theme, not let me change individual settings as I desire. It seems as though I can create my own color scheme, but that I would have to start from scratch, when really I'd want to start with the OS X graphite theme, because that one works just fine for me, with the exception of the active tab color for certain applications. Anyone know how to solve this one?
    Thanks for the help.

    I'm trying to make a small adjustment to my color theme. If you have used X-Chat Aqua, you'll notice that in the Blue OS X color theme, highlighted tabs are in blue, and easily identified. However, when the color scheme is grey, highlighted tabs are in a slightly darker grey, so I have to tilt my display back and forth to tell which tab is the active one. I prefer the grey theme, but want to change the highlighting color of the active tab. This does not have anything to do with the highlighting color in the OS X settings as I already have that set to turquoise. Does anyone know how to change this? Someone suggested Magnifique, but that seems like it will only install a whole new color theme, not let me change individual settings as I desire. It seems as though I can create my own color scheme, but that I would have to start from scratch, when really I'd want to start with the OS X graphite theme, because that one works just fine for me, with the exception of the active tab color for certain applications. Anyone know how to solve this one?
    Thanks for the help.

  • Changing Colors of selected tab in JTabbedPane.

    Do someone has some code that can show how to
    change the color of the selected tab with JTabbedPane.
    I can change the other tabs colors with setBackground and setForeground, setBackgroundAt........ but it is the selected
    tab that will not change from the default grey color.
    thanks

    try this code, it works.
    public class TabBackgroundChange extends JFrame {
    private JTabbedPane tabPane = null;
    public static final Color selTabColor = Color.red;
    Color nonSelectedTabColor = null;
    public TabBackgroundChange() {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch(Exception ex) {
    ex.printStackTrace();
    tabPane = new JTabbedPane();
    tabPane.add("One", new JPanel());
    tabPane.add("Two", new JPanel());
    tabPane.add("Three", new JPanel());
    this.getContentPane().add(tabPane);
    this.setSize(200, 200);
    this.setVisible(true);
    tabPane.addChangeListener(new TabChangeListener());
    tabPane.setSelectedIndex(1);
    tabPane.setSelectedIndex(0);
    public static void main(String[] args) {
    TabBackgroundChange tabBackgroundChange1 = new TabBackgroundChange();
    private class TabChangeListener implements ChangeListener {
    public void stateChanged(ChangeEvent ce) {
    int iSelTab = tabPane.getSelectedIndex();
    Color unSelectedBackground = tabPane.getBackgroundAt(iSelTab);
    for(int i=0; i<tabPane.getTabCount(); i++) {
    tabPane.setBackgroundAt(i, unSelectedBackground);
    tabPane.setBackgroundAt(iSelTab, Color.red);
    }

  • Setting the color on selected Tab

    Hi,
    I can't seem to figure out how to set the color on the
    selected tab in a JTabbedPane. I've added a
    ChangeListener but when I try to use it, it only
    changes the color after the tab has been selected.
    I want to change it while it is selected.
    How can I do this?

    Maybe this helps:
    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    Kurta

  • Color of selected tab panel tab

    Hello all,
    I'd like to know the orange like color of the upper part of a selected tab panel tab, see the picture below.
    Actually, these are two colors, orange and a darker, 'shaded' orange. I don't mind which color value I can obtain, but I'd like to use the same color for other controls (LED, decoration frame) as well.
    Does this color depend on the Windows theme? If so, I'd be happy about a possibility of obtaining this property programmatically.
    If this color is always the same, I can obtain it myself using Photoshop...
    Thanks a lot,
    Wolfgang
    Solved!
    Go to Solution.

    When the panel has ATTR_CONFORM_TO_SYSTEM_THEME set, CVI lets Windows draw the tabs by calling DrawThemeBackground with partIDs such as TABP_TABITEM, etc. The picture that you posted is the XP theme. The Windows 7 theme is different and it looks like this...
    I checked out the Windows function GetSysColor, but didn't see a way to get that color. Anyway, since the tabs draw differently on XP and Vista/Windows 7, you may not want to use that color in different controls.

  • Creating a Dynamic Update Statement based on Select

    hi,
    i'm trying to create a dynamic update statement based on select statement
    my requirment is to query a joint tables and get the results then based on the results i need to copy all the data and create an update statement for each row
    for ex
    the update statement should look like this
    update iadvyy set SO_SWEEP_CNT = '1' where inst_no = '003' and memb_cust_no = 'aaaaaaaaaaaaaaaa';
    and the select statement like the following
    select substr(key_1,11,9) account_no,sord_mast SO_SWEEP_CNT from
    select acct_no,count(*) sord_mast from
    (select from_acct_no acct_no,update_mast
    from sord where FROM_SYS in ('DEP','INV') and TERM_DATE > 40460
    union all
    select to_acct_no acct_no,update_mast
    from sord where TO_SYS in ('DEP','INV') and TERM_DATE > 40460)
    group by Acct_no)
    right outer join
    invm
    on
    key_1 = '003'||acct_no
    where sord_mast > 0;
    so taking the above two columns from the above select statement and substitue the values as separate update statement.
    is that doable , please share your knowledge with me if poosible
    thanks in advanced

    is that doable , please share your knowledge with me if poosibleyes
    The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the SQL before passing it to EXECUTE IMMEDIATE.
    COPY the statement & PASTE into sqlplus to validate its correctness.

  • Tab Set Label Colors - How do I change the selected tab label color?

    No matter what color I tell it to use for the Labels - Selected color I get white.  Is this a known bug in the system or am I not doing something correct.  I have a tab set component and a label based menu selector component on my display.  I've set up the labels and backgrounds for both components exactly the same but I can only get white for the selected tab set label.
    Edited by: Maureen LaComb on Feb 19, 2009 5:38 PM

    Hi, Maureen
    You can set the color of Tab Set by using the Following Steps.
    --> Select the Tab Set
    --> From the the Properties Window
    --> Select Appearance
    --> There are Two Tabs "Text" and "Color"
    --> From the Color Tab you can Select the Background Color
    --> Tab BackGrounds Or Labels from here you can select the color.
    But this setting will Apply to all the Tabs in a Tab Set, I think you can't set the Specific Setting for a single Tab in a Tab Set.
    Please Reply if any Issue,
    Kind Regards,
    Faisal

  • Why isn't the selected tab title bold in JTabbedPane? How can I make it be?

    The selected tab title of JTabbedPanel is not bold. Is there a simple way to set it to be bold when a tab is selected? Thanks in advance.

    1. Simply use the HTML code in it's text like '<html><b>NameOfThisTab</b></html>'.
    2. Extend the JTabbedPane and fine-tune the font it uses.

  • JTabbedPane - not selecting newly added tabs

    Is there a way to make it so that newly added tabs in a JTabbedPane are not automatically selected as they are added?
    Thanks,
    Adam

    I don't understand what you mean! It's just the normal behavior addTab and insertTab have! So what do you mean? insertTab remembers the currently selected tab and after adding the new tab tries selecting that one again. Maybe you select the new component after adding it.
    --Rasta                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to insure selected tabs are visible in JTabbedPane

    Hello all,
    How can you insure that the selected tab in a JTabbedPane is visible.
    Here is the code:
    import javax.swing.*;
    import java.awt.*;
    public class TabbedPaneTest extends JTabbedPane implements Runnable
    public TabbedPaneTest()
    super(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    } // end TabbedPaneTest constructor
    public void run ()
    for (int i = 1; i <= 10; i ++)
    try
    this.addTab(Integer.toString(i), createDefaultPanel (i));
    this.getModel().setSelectedIndex(i - 1);
    Thread.sleep(3000);
    } // end try block
    catch (Exception e)
    e.printStackTrace();
    } // end catch block
    } // end for loop
    } // end run method
    private JPanel createDefaultPanel (int index)
    JPanel defaultPanel = new JPanel ();
    defaultPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), Integer.toString(index)));
    return defaultPanel;
    } // end createDefaultPanel method
    public static void main (String args [])
    JFrame frame = new JFrame ();
    TabbedPaneTest tpt = new TabbedPaneTest ();
    frame.getContentPane().add(tpt);
    frame.setSize(200, 200);
    Thread newThread = new Thread (tpt);
    newThread.start();
    frame.setVisible(true);
    } // end main method
    } // end TabbedPaneTest class
    I've crated a JTabbedPane with the tabLayoutPolicy set to JTabbedPane.SCROLL_TAB_LAYOUT.
    If I add enough tabs the scroll buttons appear but the newly adde tab is hidden behind them,
    even though I have set the selection index to the added tab. The content of the panel associated
    with the tab is visible but the tab itself is hidden.
    So the selected tab is hidden behind the scroll buttons.
    Any one know how to insure that if a tab is selected it is visible to the user.
    Thanks

    This is an interesting question so I tried it out. After some poking around to see how Swing does this for mouse clicking (try setting things up so that a tab is only partially visible and then click on the visable part - notice how the whole tab is scrolled into view) I found this:    /**
         * This inner class is marked "public" due to a compiler bug.
         * This class should be treated as a "protected" inner class.
         * Instantiate it only within subclasses of BasicTabbedPaneUI.
        public class TabSelectionHandler implements ChangeListener {
            public void stateChanged(ChangeEvent e) {
                JTabbedPane tabPane = (JTabbedPane)e.getSource();
                tabPane.revalidate();
                tabPane.repaint();
                if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
                    int index = tabPane.getSelectedIndex();
                    if (index < rects.length && index != -1) {
                        tabScroller.tabPanel.scrollRectToVisible(rects[index]);
        }Which is called when the selected tab changes. The member theScroller is a private inner class that handles the scrolling tabs. The call to scrollRectToVisible is executed for each of your new tabs. Sometimes when I stopped in the debugger and then continued things worked and your new tab scrolled into view.
    So I tried putting your code into a Runnable class and invoked it later:          final int newIndex = i;
              SwingUtilities.invokeLater (new Runnable ()  {
                   public void run ()  {
                        addTab(Integer.toString(newIndex), createDefaultPanel (newIndex));
                        getModel().setSelectedIndex(newIndex - 1);
              });But that did not work. That is as far as I got so far and I have to stop now. Perhaps this can inspire someone else to a solution.
    IL
    PS. I first tried Rammensee's solution and it did not work.
    Rammensee, you said you hoped you had it right - perhaps you are close.

  • JTabbedPane - vertical - which tab is selected?

    Using the Windows L&F, if you have the tabs in a JTabbedPane arranged horizontally it is clear and obvious which tab is selected. But with the tabs arranged vertically you've got to look very carefully to see which tab is selected, as there are rather fewer changes than for horizontal tabs.
    I can't be the first person whose users have complained about this - what's the conventional solution?
    (One thought is to make the background colour of the non-selected tabs "a bit darker"; I guess that would look OK but wouldn't mind a pointer as to how to do this in such a fashion that it will still work when the user changes the desktop colour scheme.)

    Using the Windows L&F, if you have the tabs in a JTabbedPane arranged horizontally it is clear and obvious which tab is selected. But with the tabs arranged vertically you've got to look very carefully to see which tab is selected, as there are rather fewer changes than for horizontal tabs.
    I can't be the first person whose users have complained about this - what's the conventional solution?
    (One thought is to make the background colour of the non-selected tabs "a bit darker"; I guess that would look OK but wouldn't mind a pointer as to how to do this in such a fashion that it will still work when the user changes the desktop colour scheme.)

  • JTabbedPane selected tab size

    Hello everybody;
    I've created a JTabbedPane with JLabel on each tab and i want that the selected one size be larger than the other tabs.
    The problem is that if I increase the size of the selected tab, all the others (inselected tabs) do so (they take the same size as the selected one) which is normal.
    My need is to change this default behavior in order to fix the inselected tab size and increase the selected one to appear bigger
    Thank you for your help

    Hello,
    - JDK 6
    - MetalLookAndFeel
    - JTabbedPane#getTabPlacement()==TOP
    - Selected tab "width" only grow
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SelectedTabSizeTest{
      private static void addTab(JTabbedPane t, String title, Component c) {
        t.addTab(title, c);
        JLabel label = new JLabel(title, SwingConstants.CENTER);
        t.setTabComponentAt(t.getTabCount()-1, label);
      public JComponent makeUI() {
        JTabbedPane t = new JTabbedPane() {
          private void initTabWidth() {
            int tabCount  = getTabCount();
            if(tabCount==0) return;
            int bigger   = 50;
            int tabWidth = 30;
            int si = getSelectedIndex();
            for(int i=0;i<tabCount;i++) {
              JLabel l = (JLabel)getTabComponentAt(i);
              if(l==null) continue;
              int w = tabWidth+(si==i?bigger:0);
              int h = l.getPreferredSize().height;
              l.setPreferredSize(new Dimension(w, h));
          @Override public synchronized void repaint() {
            initTabWidth();
            super.repaint();
        t.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        addTab(t, "JTree",      new JScrollPane(new JTree()));
        addTab(t, "JTextArea",  new JScrollPane(new JTextArea("aaaa")));
        addTab(t, "Preference", new JScrollPane(new JTree()));
        addTab(t, "Help",       new JScrollPane(new JTextArea("bbbbbb")));
        t.setPreferredSize(new Dimension(320, 200));
        return t;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() { createAndShowGUI(); }
      public static void createAndShowGUI() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.getContentPane().add(new SelectedTabSizeTest().makeUI());
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

  • Stopping right click selecting tab in JTabbedPane

    Hello all,
    This may be a really simple thing + I'm probably being thick, but is there a way to prevent a right click changing the selected tab on a JTabbedPane.
    I tried consuming the MouseEvent, but that didn't seem to work. Couldn't find an answer anywhere else in the forums & couldn't see anything in the JavaDoc that looked as if it would help.
    Answers on a postcard please......
    RT

    You might be able to extend JTabbedPane and override setSelectedIndex().
    I had to do this to work around a focus issue I had.
      This class extends JTabbedPane to correct a problem where it doesn't
      request focus when clicked on.
    import java.awt.*;
    import javax.swing.*;
    public class MyJTabbedPane extends JTabbedPane {
      public void setSelectedIndex(int index) {
        Component comp = KeyboardFocusManager.
            getCurrentKeyboardFocusManager().getFocusOwner();
        //  if  no tabs are selected
        // -OR- the current focus owner is me
        // -OR- I request focus from another component and get it
        // then proceed with the tab switch
        boolean noTabSelected = getSelectedIndex()==-1;
        boolean hasFocus = requestFocus(false);
        boolean compIsMe = comp==this;
        if(noTabSelected || hasFocus || compIsMe) {
          super.setSelectedIndex(index);
    }

  • Tab information dynamically on select

    Hi,
       How do we get the information regarding the SelectedTab dynamically .I have refer some blogs but i am unable to get my information .When we have 2 Tabs(tab1,tab2).if in default i am in Tab1 then when i click on tab2 i created an action but i donot know how to fetch the value of current tab.
    Regards,
    Amit

    Hi AMITTEJA VUTPALA
    Write this piece of code in the onselect event of tabstrip UI element
    For getting the selected tab .
    data : ls_parameter TYPE  wdr_event_parameter_list,
             ls_tab TYPE wdr_event_parameter,
              lv_value TYPE string .
       ls_parameter = wdevent->parameters .
    LOOP AT  ls_parameter INTO ls_tab WHERE  name = 'TAB'.
       CALL METHOD wdevent->get_string
          EXPORTING
            name  = 'TAB'
          RECEIVING
            value = lv_value.  " here you will get the selected Tab ID name .
      endloop.
    For getting the Previous tab ID
    data : ls_parameter TYPE  wdr_event_parameter_list,
             ls_tab TYPE wdr_event_parameter,
              lv_value TYPE string .
       ls_parameter = wdevent->parameters .
    LOOP AT  ls_parameter INTO ls_tab WHERE  name = 'OLD_TAB'.
       CALL METHOD wdevent->get_string
          EXPORTING
            name  = 'OLD_TAB'
          RECEIVING
            value = lv_value.  " here you will get the selected PreviousTab ID name .
      endloop.
    Hope it will help you
    Regards
    Chinnaiya P

Maybe you are looking for