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.

Similar Messages

  • 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.

  • Working on a simple doc with a title, an attribution slug, and a pic.  Don't see to be able to select/move title text box

    Don't seem to be able to select or move the title text box.  Have tried calling it  other things (freeform, Heading 2, etc.) with no success.  What's the trick to select and move?
    Thanks,
    Frank

    QXP = QuarkXpress not QK.
    Pages 5 does not allow textbox linking which is a real PITA.
    Even Pages '09 which does allow it works differently than QXP, but actually has quite good layout features. For certain of my projects Pages '09 is much faster than QXP, although without all the bells and whistles.
    No way that Pages 5 is even a vague substitute for QXP in fact it is a slow moving buggy disaster if you look in these forums and in the App Store reviews.
    It sounds like you are trying to create a commercial print file. Do not do this in Pages!
    Pages can create commercial files but with a great deal of problems and difficulties. The full process is a long story and probably not for you. No way I would use Pages 5 it has so many things that don't work and go wrong.
    Peter

  • 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

  • How to change the selected tabPane title color in JTabbedPane

    how to change the selected tabPane title color(or set bold) in JTabbedPane.
    Any advice will be appreciate.

    Hi,
    try
    // Set text color for the selected tab
    tab.setForegroundAt(tab.getSelectedIndex(), Color.red);Hope that helps

  • Javascript to put text of selected tab in a header element at top of page

    Create a simple html document a header and main div's.   tab menu, say three tabs, in the main div.  Want the header to display the text of the selected tab.
    Here is the example with default SpryTabbedPanels.js and SpryTabbedPanels.css.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="header">Content for  id "header" Goes Here :Want this to be the text of the selected tab.</div>
    <div id="main">
      <div id="TabbedPanels1" class="TabbedPanels">
        <ul class="TabbedPanelsTabGroup">
          <li class="TabbedPanelsTab" tabindex="0">Tab 1 text</li>
          <li class="TabbedPanelsTab" tabindex="0">Tab 2 text</li>
          <li class="TabbedPanelsTab" tabindex="0">Tab 3 text<br />
          </li>
        </ul>
        <div class="TabbedPanelsContentGroup">
          <div class="TabbedPanelsContent">Content 1</div>
          <div class="TabbedPanelsContent">Content 2</div>
          <div class="TabbedPanelsContent">Content 3</div>
        </div>
      </div>
      main content
    </div>
    <script type="text/javascript">
    <!--
    var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
    //-->
    </script>
    </body>
    </html>
    Anyone have a javascript for this?

    Just to clarify:

  • Fix tab title size in JTabbedPane

    Now, each tab in my JTabbedPane occupies the whole row because the title is too long. Is there any way to set each tab title size to be preferred fixed size in JTabbedPane? (I can use the tooltip to show the whole string. )
    Thanks.

    Swing related questions should be posted in the Swing forum.
    You will probably need to write your own UI. The TabbedPaneUI has a getTabBounds method you could probably override.
    Otherwise just set the tab text manually to be a certain number of characters. You can store the full text in a variable that is referenced by your tool tip logic.

  • 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);
    }

  • 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);
    }

  • 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.

  • When I select a title or lower thirds and try to enter text by double clicking on it I cannot enter any text at all. Also the text area box does not show up at all where you can enter text also.

    When I select a title or lower thirds and try to enter text by double clicking on it I cannot enter any text at all. Also the text area box does not show up at all where you can enter text also.

    It's a bit hit and miss, Walter. Sometimes the box to enter text shows up straight away in the inspector under "text". Other times, although you click "text" in the inspector, there's nowhere to actually write anything.... then what you have to do is move the trackbar over the Title Box until you see the text boxes in the main Viewer. In the Viewer, double click a text box.... you can enter text there, but it's a bit flaky, but when you've clicked in it, you'll find that under "Text" in the inspector, the box for inputting text has magically appeared!
    I'm not sure if anyone else has this trouble, but it is a bit of a pain!

  • 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.)

  • 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);
    }

  • How to put a title of a group of controls with no line below title text?

    Hi,
    Is there any way to write a title of a group of controls and indicators made by "chiselled line", such that the chiselled line remain invisible below the title text and remain visible everywhere else? For example, the titles "Printer", "Page Range", "Copies", and "Zoom" in a Microsoft Word form in the attached PDF file; note that there is no line below the title text and there is no text box surrounding the title text. I want to have that kind of title of the group of controls and indicators in a GUI of my LabVIEW application.
    Any help will be appreciated.
    Thanks.
    Javed
    Solved!
    Go to Solution.
    Attachments:
    Examples of Group Title.pdf ‏45 KB

    Hi Rod,
    Thanks for your help, but I could not implement your idea. My replies to your suggestions are written in bold below.
    One way is to put your text into a System Label or a free label. Ensure that you size the box to the text in it
    Can you please explain what are "System label" and "free label"? As far as I am concerned, I first inserted a Recessed Frame from Decorations control palette. Then, I put the text using "Edit Text" tool in the Tools Palatte. The text box resizes automatically as I insert a new character in it. I wrote "Printer" in the text. Then, I went to Tools Palette, clicked on "Set Color", right-clicked on "Printer" text, clicked on "T" (Transparent) shown at the top-right position of the color palette. The result is that the text box around the text is eliminated, but still the line of the frame is making a strike-through effect. How to eliminate the line from the area of the text container. The resulting VI (using LabVIEW 8.5) is attached.
    Change the colours of the label to have a background colour the same colour as your panel background, and the foreground colour set to transparent [transparent foreground removes the box round the text]
    I think this is important. But I don't know where are the options for setting the "foreground color" and "background color".
    When you position the text, you may find that it is partly hidden by the line. If so, select the text box and bring it to the front (Control-Shift-K is the keyboard shortcut) Note: This step won't be needed if you place the line before you make the label.
    Thanks for the keyboard short-cut, but my problem is not solved yet, as shown in the attached VI.
    By the way, where did you find the frame with round corners (in the image you have provided)? The recessed frame available in LabVIEW 8.5 decoration palette does not have round corners.
    Rod
    Attachments:
    Test Example 1.vi ‏5 KB

Maybe you are looking for