Closable Tab in JTabbedPane

Hi
I trying to develop a Closable Tab in JTabbedPane. The close button should appear after/before the tab title all the time (like in JBuilder IDE).
I know the trick where close button appears when the mouse is in that area, but i want it to be displayed all the time irrespective of the mouse position.
How i should be able to create this component??
I am very new to swing please help...
Thanks for your help...
-Vinod

Thanks Stas,
Your code was really helpfull.
I've improved it a litte bit. So I'd like to share It.
To use it, just create a ClosableTabbedPane.
If you need to change the default action (remove the tab) then use the method setCloseTabAction(CloseTabAction) to change the action.
Cheers,
Rafa
================================
The TabbedPaneUI
================================
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
public class ClosableTabbedPaneUI extends BasicTabbedPaneUI
     public final static int BUTTON_SIZE = 12;
     public final static int BORDER_SIZE = 3;
     public ClosableTabbedPaneUI()
          super();
     protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect)
          super.paintTab(g,tabPlacement,rects,tabIndex,iconRect,textRect);
          Rectangle rect=rects[tabIndex];
          int yPosition = (rect.height-BUTTON_SIZE)/2;
          int xPosition = rect.x+rect.width-Math.round(BUTTON_SIZE*1.5f);
          g.setColor(Color.BLACK);
          g.drawRect(xPosition,yPosition,BUTTON_SIZE,BUTTON_SIZE);
          g.setColor(Color.black);
          g.drawLine(xPosition+BORDER_SIZE,yPosition+BORDER_SIZE,xPosition+BUTTON_SIZE-BORDER_SIZE,yPosition-BORDER_SIZE+BUTTON_SIZE);
          g.drawLine(xPosition+BORDER_SIZE,yPosition-BORDER_SIZE+BUTTON_SIZE,xPosition+BUTTON_SIZE-BORDER_SIZE,yPosition+BORDER_SIZE);
     protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected)
          return super.getTabLabelShiftX(tabPlacement, tabIndex, isSelected)-BUTTON_SIZE;     
     protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics)
          return super.calculateTabWidth(tabPlacement,tabIndex,metrics)+BUTTON_SIZE;
     protected MouseListener createMouseListener()
          return new MyMouseHandler();
     class MyMouseHandler extends MouseHandler
          public MyMouseHandler()
               super();
          public void mouseClicked(MouseEvent e)
               int x=e.getX();
               int y=e.getY();
               int tabIndex=-1;
               int tabCount = tabPane.getTabCount();
               for (int i = 0; i < tabCount; i++)
                    if (rects[ i ].contains(x, y))
                         tabIndex= i;
                         break;
               if (tabIndex >= 0)
                    Rectangle rect = rects[tabIndex];
                    int yPosition = (rect.height-BUTTON_SIZE)/2;
                    int xPosition = rect.x+rect.width-Math.round(BUTTON_SIZE*1.5f);
                    if( new Rectangle(xPosition,yPosition,BUTTON_SIZE,BUTTON_SIZE).contains(x,y))
                         if( tabPane instanceof ClosableTabbedPane )
                              ClosableTabbedPane closableTabbedPane = (ClosableTabbedPane)tabPane;
                              CloseTabAction closeTabAction = closableTabbedPane.getCloseTabAction();
                              if(closeTabAction != null)
                                   closeTabAction.act(closableTabbedPane, tabIndex);
                         else
                              // If somebody use this class as UI like setUI(new ClosableTabbedPaneUI())
                              tabPane.removeTabAt(tabIndex);
======================================
The Closable TabbedPane
======================================
public class ClosableTabbedPane extends JTabbedPane
     private CloseTabAction closeTabAction = null;
     public ClosableTabbedPane()
          super();
          init();
     public ClosableTabbedPane(int arg0)
          super(arg0);
          init();
     public ClosableTabbedPane(int arg0, int arg1)
          super(arg0, arg1);
          init();
     private void init()
          setUI(new ClosableTabbedPaneUI());
          closeTabAction = new CloseTabAction()
               public void act(ClosableTabbedPane closableTabbedPane, int tabIndex)
                    closableTabbedPane.removeTabAt(tabIndex);
     public CloseTabAction getCloseTabAction()
          return closeTabAction;
     public void setCloseTabAction(CloseTabAction action)
          closeTabAction = action;
=========================
The Action
=========================
public interface CloseTabAction
     public void act(ClosableTabbedPane closableTabbedPane, int tabIndex);

Similar Messages

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

  • How to set a single tab in JTabbedPane invisible

    Hello,
    I want to set only a single tab invisible out of 9 tabs in JTabbedPane. I can disable the tab but not able to set invisible.
    Thanking you in advance.

    you may use JTabbedPane.removeTabAt(int) method as long as you don't want the tab to appear & when needed use JTabbedPane.insertTabAt(String, Icon, Component, String, int) method.
    as far as i know this is only way to achieve our want. this should help you.
    regards,
    Afroze.

  • Each tab of JTabbedPane has different border color

    Is it possible for the content area of each tab in JTabbedPane to have a different border color? Selecting Tab1 highlights content area of the tabbed pane in yellow, selecting tab2 highlights it in red, etc...
    Thanks

    Thanks for the quick response splungebob. How would I get a reference to the Jpanel of a specific tab? In my case each tab will have a toolbar, so I tried setting the toolbar border yellow, but I still have the default jtabbedpane border color surrounding my yellow bordered toolbar. I would prefer to set the color on the jtabbedpane, so that way the Tab itself does not also have the border going underneath it. For instance, I don't want the border to continue underneath the "my tab" tab, as illustrated below:
       | my tab |
    |                                                  |
    |                                                  |
    ----------------------------------------------------Edited by: 816886 on Nov 30, 2010 7:53 AM

  • Urgent - How to add a new control instead of tabs in JTabbedPane

    Hi,
    Please give me an idea or a sample program for how to add a new control
    in JTabbedpane instead of tabs that means overlay any Java controls or pane
    in the tabpane empty place next to tabs

    "Urgent" is not relevant to the question. Your question is no more important than anybody elses.
    My answer in this posting show a limited solution:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=636289
    Otherwise I suggest you try using a layered pane approach:
    http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html

  • How can I draw the tab of JTabbedPane as an image?(urgent)

    I would like to draw a JTabbedPane with a tab as an image or set the its size like I want.
    Any help is appreciated.

    Hi,
    you can set size the tabs by using the tabInsets key.
    Notice also the textIconGap key.
    UIDefaults ui = UIManager.getDefaults();
    ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(10,10,10,10));
    "TabbedPane.textIconGap" int
    These are the keys and values connected with TabbedPane.
    If you need further customization of the tabbed pane I would suggest building your own.
    "TabbedPane.selected", Color
    "TabbedPane.tabRunOverlay" int
    "TabbedPane.tabAreaInsets" InsetsUIResource
    "TabbedPane.shadow" ColorUIResource
    "TabbedPane.selectedTabPadInsets" InsetsUIResource
    "TabbedPane.highlight" ColorUIResource
    "TabbedPane.lightHighlight" ColorUIResource
    "TabbedPane.font" FontUIResource
    "TabbedPane.foreground" ColorUIResource
    "TabbedPane.background" ColorUIResource
    "TabbedPane.focus" ColorUIResource
    "TabbedPane.darkshadow" ColorUIResource
    "TabbedPane.contentBorderInsets" InsetsUIResource
    -Michael

  • Problem with loading tabs in JTabbedpane

    Hi,
    i am new to swing programming. I have a Jtabbedpane and i remove and add different tabs depending on the page i need to load.when i call the function which removes existing tabs and adds new one,the content of my frame changes but the new tabs gets loaded only on a "mouse click".Why is this so and could i make the tabs load automatically when i call the function?
    Any help would be appreciated..I have pasted the code below.
    void Settingfunc(){
    mainPanel.remove(tabbedPane);
    tabbedPane.removeAll();
    passwdadm();
    mainPanel.add(tabbedPane);
    void passwdadm(){
    panelfin = new JPanel();
    panelfin1.setLayout(new BorderLayout());
    JComponent panel1 = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    panel1.setLayout(gridbag);
    tabbedPane.addTab("Password", bot1, panelfin,
    "Does nothing");
    final JCheckBox chkbox1 = new JCheckBox("", true);
    chkbox1.setFont(new Font("Arial",Font.PLAIN,12));
    constraints.gridx=0;
    constraints.gridy=0;
    constraints.insets.top=20;
    gridbag.setConstraints(chkbox1,constraints);
    panel1.add(chkbox1);
    JLabel lnch=new JLabel("Require password to open program");
    lnch.setFont(new Font("Arial",Font.PLAIN,12));
    constraints.gridx=1;
    constraints.anchor=GridBagConstraints.WEST;
    constraints.gridy=0;
    gridbag.setConstraints(lnch,constraints);
    panel1.add(lnch);
    panelfin.add(panel1,BorderLayout.NORTH);
    }

    1) Post code using the "formatting tags" so your original formatting is retained.
    If you only want to replace the tabs in the tabbed pane then there is no need to use:
    mainPanel.remove(tabbedPane);  // not needed
    tabbedPane.removeAll();
    passwdadm();
    mainPanel.add(tabbedPane); // not neededHowever, if for some reason you feel you need to remove/add a component to a container then you need to revalidate the container so it can layout the components correctly. Something like:
    container.remove(...)
    container.add(....)
    container.revalidate();

  • Thumbnail view of  tabs in JTabbedPane

    Hi all,
    I am doing a desktop app . In my app i am using JTabbedPane . In order to view the contents of all tabs in one shot,i need to bring the JPanel in each tab into a single frame,that contains a scrollbar.i.e,something like a thumbnail view of all the tabs.Is it possible to do so? Since i have several components like button, textbox,images,etc in each tab,and have set the layout property of the panel to null,i cannot reduce the size of the panel to thumbnail size.I have set layout property of jpanel in each tab to null,because i have enabled dragging of objects like buttons,textarea,images,etc.Can anyone help me to sort out this problem.
    Thanks in advance
    Ravisenan

    Ok - you only gave iPhoto '11 - I assumed up to date
    Glad you found it anyway
    You are welcome
    LN

  • Help with disabling close icon of last opened tab in JTabbedPane

    Hello
    Would someone help me out ? I have 3 tabs opened in a JTabbedPane, each with close icon "X". I am looking for a way to tell my program: if the user closes 2 tabs and only 1 remain, disable the close icon "X" of the last opened tab so that the user is unable to close the last tab. I have searched the forum, most I have run into are how to create the close icon. Would someone give me some insight into how to go about doing this? or if you have come across a forum that discusses this, do please post the link. Also, I am using java 1.6.
    Thanks very much in advance

    On each close, look how many tabs are remaining open in the JTabbedPane (getTabCount).
    If there is only one left, set its close button to invisible. Something like this:
    if (pane.getTabCount() == 1) {
        TabCloseButton tcb = (TabCloseButton) pane.getTabComponentAt(0);
        tcb.getBtClose().setVisible(false);
    }

  • Focus-requests when switching tabs in JTabbedPane

    I have a tabbed pane with a JTextArea in each tab. I would like to switch focus to the corresponding area each time I select a tab or create a new one. A ChangeListener can detect tab selections and call requestFocusInWindow() on the newly chosen tab's text area.
    For some reason, the focus only switches sporadically. Sometimes the caret appears to stay, sometimes it only blinks once, and sometimes it never appears. My friend's workaround is to call requestFocusInWindow() again after the setSelectedIndex() calls, along with a Thread.sleep() delay between them. Oddly, in my test application the delay and extra focus-request call are only necessary when creating tabs automatically, rather than through a button or shortcut key.
    Does the problem lie in separate thread access on the same objects? I tried using "synchronized" to no avail, but EventQueue.invokeLater() on the focus request worked. Unfortunately, neither the delay nor invokeLater worked in all situations in my real-world application. Might this be a Swing bug, or have I missed something?
    Feel free to tinker with my test application:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    /**Creates a tabbed pane with scrollable text areas in each tab.
    * Each time a tab is created or selected, the focus should switch to the
    * text area so that the cursor appears and the user can immediately type
    * in the area.
    public class FocusTest2 extends JFrame {
         private static JTabbedPane tabbedPane = null;
         private static JTextArea[] textAreas = new JTextArea[100];
         private static int textAreasIndex = 0;
         private static JButton newTabButton = null;
         /**Creates a FocusTest2 object and automatically creates several
          * tabs to demonstrate the focus switching.  A delay between creating
          * the new tab and switching focus to it is apparently necessary to
          * successfully switch the focus.  This delay does not seem to be
          * necessary when the user fires an action to create new tabs, though.
          * @param args
         public static void main(String[] args) {
              FocusTest2 focusTest = new FocusTest2();
              focusTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              focusTest.show();
              //Opens several tabs.
              for (int i = 0; i < 4; i++) {
                   try {
                        //adding the tab should automatically invoke setFocus()
                        //through the tabbed pane's ChangeListener, but for some
                        //reason the focus often doesn't switch or at least doesn't
                        //remain in the text area.  The workaround is to pause
                        //for a moment, then call setFocus() directly
                        addTabbedPaneTab();
                        //without this delay, the focus only switches sporadically to
                        //the text area
                        Thread.sleep(100);
                        setFocus();
                        //extra delay simply for the user to view the tab additions
                        Thread.sleep(1900);
                   } catch (InterruptedException e) {
         /**Adds a new tab, titling it according to the index of its text area.
          * Using "synchronized" here doesn't seem to solve the focus problem.
         public static void addTabbedPaneTab() {
              if (textAreasIndex < textAreas.length) { //ensure that array has room
                   textAreas[textAreasIndex] = new JTextArea();
                   //title text area with index number
                   tabbedPane.addTab(
                        textAreasIndex + "",
                        new JScrollPane(textAreas[textAreasIndex]));
                   tabbedPane.setSelectedIndex(textAreasIndex++);
         /**Constructs the tabbed pane interface.
         public FocusTest2() {
              setSize(300, 300);
              tabbedPane = new JTabbedPane();
              //Action to create new tabs
              Action newTabAction = new AbstractAction("New") {
                   public void actionPerformed(ActionEvent evt) {
                        addTabbedPaneTab();
              //in my real-world application, adding new tabs via a button successfully
              //shifted the focus, but doing so via the shortcut key did not;
              //both techniques work here, though
              newTabAction.putValue(
                   Action.ACCELERATOR_KEY,
                   KeyStroke.getKeyStroke("alt T"));
              newTabAction.putValue(Action.SHORT_DESCRIPTION, "New");
              newTabAction.putValue(Action.MNEMONIC_KEY, new Integer('T'));
              newTabButton = new JButton(newTabAction);
              Container container = getContentPane();
              container.add(tabbedPane, BorderLayout.CENTER);
              container.add(newTabButton, BorderLayout.SOUTH);
              //switch focus to the newly selected tab, including newly created ones
              tabbedPane.addChangeListener(new ChangeListener() {
                   public void stateChanged(ChangeEvent evt) {
                        //note that no delay is necessary for some reason
                        setFocus();
         /**Sets the focus onto the selected tab's text area.  The cursor should
          * blink so that the user can start typing immediately.  In tests without
          * the delay during the automatic tab creation in main(), the cursor
          * sometimes only blinked once in the text area.
         public static void setFocus() {
              if (tabbedPane == null) //make sure that the tabbed Pane is valid
                   return;
              int i = tabbedPane.getSelectedIndex();
              if (i < 0) //i returns -1 if nothing selected
                   return;
              int index = Integer.parseInt(tabbedPane.getTitleAt(i));
              textAreas[index].requestFocusInWindow();
    }

    Did you ever get everything figured out with this? I have a similar problem ... which I have working, but it seems like I had to use a bunch of hacks.
    I think the problem with the mouse clicks is because each event when you click the moues (mousePressed, mouseReleased, mouseClicked) causes the tab to switch, and also these methods are called twice for some reason - for a total of 8 events giving the tab the focus instead of your textarea.
    This works, but seems aweful hacky:
         class TabMouseListener extends MouseAdapter
              private boolean switched = false;
              public void mousePressed( MouseEvent e ) { checkPop( e ); }
              //public void mouseReleased( MouseEvent e ) { checkPop( e ); }
              //public void mouseClicked( MouseEvent e ) { checkPop( e ); }
              public void checkPop( MouseEvent e )
                   if( e.isPopupTrigger() )
                        mousex = e.getX();
                        mousey = e.getY();
                        int index = tabPane.indexAtLocation( mousex, mousey );
                        if( index == -1 ) return;
                        tabMenu.show( tabPane, mousex, mousey );
                   else {
                        if( !switched )
                             switched = true;
                             e.consume();
                             int index = tabPane.indexAtLocation( e.getX(), e.getY() );
                             if( index != -1 )
                                  tabPane.setSelectedIndex( index );
                                  TabFramePanel panel = (TabFramePanel)tabPane.getComponentAt( index );
                                  if( panel != null ) panel.getInputComponent().requestFocus();
                        else {
                             switched = false;
                             TabFramePanel panel = (TabFramePanel)tabPane.getSelectedComponent();
                             if( panel != null ) panel.getInputComponent().requestFocus();
         }Do you know of a better way yet?
    Adam

  • Adding tab in JTabbedPane

    I'm confused as to how to add a tab. This is the code I wrote (I got it from my textbook):
    JTabbedPane tp = new JTabbedPane();
    tp.addTab (listName, new BorderPanel());
    And this is the error I am getting:
    cannot find symbol
    symbol : method addTab(java.lang.String,BorderPanel)
    location: class javax.swing.JTabbedPane
    tp.addTab (listName, new BorderPanel());
    I've imported the following into this file:
    java.awt.*;
    javax.swing.*;
    javax.swing.border.*;

    Read the JTabbedPane API for a description of all the methods and the parameters they accept.
    You will also find a link to the Swing tutorial on "How to Use Tabbed Panes" which has a working example.

  • Insert tab in jTabbedPane problem

    Hi,
    I am trying to insert a tab into a JTabbedPane using this method:
    insertTab(String title, Icon icon, Component component, String tip, int index)
    It works fine - the tab is inserted to the right place on the GUI, but the problem is this - though the tab is inserted at the right location in the GUI, when I traverse through the JTabbbedPane, I see that the new tab is inserted at the last index!
    Can someone let me know how to fix this problem?
    Thanks

    Here is the example code:
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextArea;
    public class TabbedPaneTest {
        public static void main(String[] args) {
            JTabbedPane tp = new JTabbedPane();
            tp.add("tab0", new JPanel());
            tp.add("tab2", new JPanel());
            tp.add("tab3", new JPanel());
            tp.insertTab("tab1", null, new JTextArea(), null, 1);
            for (int i=0; i<tp.getComponentCount(); i++) {
                System.out.println("TabComponent"+i+": "+tp.getComponent(i));
    }The output of this test program is:
    TabComponent0: javax.swing.JPanel...
    TabComponent1: javax.swing.JPanel...
    TabComponent2: javax.swing.JPanel...
    TabComponent3: javax.swing.JTextArea...
    You can see that the JTextArea is not inserted at index 1 as expected.
    But I found the solution for this problem myself. If you replace tp.getComponent(i) by
    tp.getComponentAt(i) the program output is:
    TabComponent0: javax.swing.JPanel...
    TabComponent1: javax.swing.JTextArea...
    TabComponent2: javax.swing.JPanel...
    TabComponent3: javax.swing.JPanel...
    and this is what I need!!!

  • Change Color of Disable Tab in JTabbedPane

    Hello Friends,
    I have one JTabbedPane in my Application.
    In that one Tab is Disable.
    I want to change default Background and Foreground color of that tab.
    Can u help me...
    Thanks in Advance,
    Nishith Shah.

    hii,
    please I can't find out any DisableColor or something similair for defaultTabbedPaneUI, please try (unselect)
    package jtabs;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Insets;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    import javax.swing.plaf.ColorUIResource;
    public class TestTabbedPane extends JFrame {
        JTabbedPane tabbedPane;
        public TestTabbedPane() {
            tabbedPane = new JTabbedPane();
            tabbedPane.setPreferredSize(new Dimension(300, 200));
            getContentPane().add(tabbedPane);
            JPanel panel = new JPanel();
            tabbedPane.add(panel, "null");
            JTextField one = new JTextField("one");
            tabbedPane.add(one, "one");
            JTextField two = new JTextField("two");
            tabbedPane.add(two, "two");
            tabbedPane.setEnabledAt(2, false);
            /*UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
            UIManager.put("TabbedPane.highlight", new Color(255, 0, 0));
            UIManager.put("TabbedPane.lightHighlight", new Color(0, 255, 0));
            UIManager.put("TabbedPane.darkShadow", new Color(0, 255, 0));
            UIManager.put("TabbedPane.shadow",new Color(0, 0, 255));
            UIManager.put("TabbedPane.light" ,  new Color(0, 255, 0));
            UIManager.put("TabbedPane.foreground", new Color(0, 0, 0));
            UIManager.put("JTabbedPane.font", new Font("Dialog", Font.ITALIC, 12));
            UIManager.put("TabbedPane.selected", new Color(255, 0, 0));
            UIManager.put("disable", new Color(255, 0, 0));
            UIManager.put("TabbedPane.selectHighlight" , new Color(0, 0, 0));*/
            //UIManager.put("TabbedPane.background",  new Color(0, 0, 0));
            //SwingUtilities.updateComponentTreeUI(tabbedPane);
            /*tabbedPane.setTitleAt(2, "<html><font color=" +
                    (tabbedPane.isEnabledAt(2) ? "black" : "red") + ">" +
                    tabbedPane.getTitleAt(2) + "</font></html>");*/
        public static void main(String args[]) {
            TestTabbedPane frame = new TestTabbedPane();
            frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
    } value are from
    import javax.swing.*;
    import java.util.*;
    public class GetUIManagerList {
        public static void main(String[] args) {
            UIDefaults defaults = UIManager.getDefaults();
            System.out.println(defaults.size() + " properties defined !");
            System.out.println("-----------------------------------");
            String[] colName = {"Key", "Value"};
            String[][] rowData = new String[defaults.size()][2];
            int i = 0;
            for (Enumeration e = defaults.keys(); e.hasMoreElements(); i++) {
                Object key = e.nextElement();
                rowData[ 0] = key.toString();
    rowData[i][ 1] = "" + defaults.get(key);
    System.out.println(rowData[i][0] + " ,, " + rowData[i][1]);
    please could I ask camickr or DarrylBurke how to overide disabled label in JTabbedPane (without Shadows), with using their SwingUtils
    ... kopik                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How can I add some space between each tab in JTabbedPane?

    I added some tabs in a JTabbedPane and want to add some spaces between each of them. How can I do this?

    There are different questions, aren't they? if you ask how to move a component to the right, and get an answer,
    then ask how to move it lower, it may seem to be a different question,
    but the concept is the same, and the answer would almost certainly
    be the same (with a tweak). Basically you should be smart enough to work
    out how to move it lower for yourself.
    if you don't understand the how concept of my response in the linked post
    relates to this post, then you're in the wrong game.
    to make it easier for you to understand
    set your own UI, overriding calculateTabHeight(..), setting whatever you want
    set your own UI, overriding paintTab(..), setting whatever you want for rects[..].x
    having pointed you to the area where you do this stuff, you should have been
    smart enough to work it out for yourself.
    at some point you will have to take your feet off the desk.

  • Custom tabs for JTabbedPane?

    Is there no way to customize the contents of a tab for a JTabbedPane? I mean, sure, icon and label are nice. But say I want a "X" button on it to close the tab. Is there no way to do something like that?
    It would seem like a useful thing to have a JTab component that is a container which displays the tab itself. The default contents could be a JLabel for the icon/label, but then if I wanted to add a button, I could do so.
    Maybe I'm missing something, but I don't think so. I've searched around and don't see any way (I'm not even sure that a customized TabbedPaneUI would even work here)...

    Check this out: http://www.infonode.net/index.html?itp
    This JTabbedPane alternative is designed just as you described: each tab is a separate component, containing the label, icon, etc., plus the "content" component. Adding a button that removes the tab is trivial, as shown below. Another feature I'm particularly fond of is the "compression" layout policy, which squeezes the tabs to fit the available width. I much prefer that scheme to scrolling tabs, and they've implemented it very nicely.
    The only quibble I have with it is the way it handles keyboard focus. Either I'm missing something, or it just doesn't work sensibly. The sample code includes a workaround that forces the selected content component to always have the focus.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import net.infonode.tabbedpanel.*;
    import net.infonode.tabbedpanel.titledtab.*;
    public class TabbedPanelDemo
      public static void main(String[] args)
        // Reduce padding around tabs, especially to the right of the
        // the "remove" button.  If there's a way to do this through
        // the TabbedPanel API, I haven't found it.
        UIManager.put("TabbedPane.tabInsets", new Insets(0, 5, 1, 1));
        JFrame frame = new JFrame("TabbedPanelDemo");
        frame.addWindowListener(
          new WindowAdapter()
            public void windowClosing(WindowEvent e)
              System.exit(0);
        final TabbedPanel tp = new TabbedPanel();
        tp.getProperties().setTabLayoutPolicy(TabLayoutPolicy.COMPRESSION);
        tp.addTab(makeTab("First Panel",  "Panel 1"));
        tp.addTab(makeTab("Second Panel", "Panel 2"));
        tp.addTab(makeTab("Third Panel",  "Panel 3"));
        tp.addTab(makeTab("Fourth Panel", "Panel 4"));
        tp.addTab(makeTab("Fifth Panel",  "Panel 5"));
        // Keep the focus in the selected textarea.  If you comment out
        // this statement, the focus will shift to the the Close button
        // every time you select a different tab.
        tp.addTabListener(
          new TabAdapter()
            public void tabSelected(TabStateChangedEvent evt)
              tp.getSelectedTab().getContentComponent().requestFocus();
            public void tabRemoved(TabRemovedEvent evt)
              tp.getSelectedTab().getContentComponent().requestFocus();
        frame.add(tp, BorderLayout.CENTER);
        Box box = Box.createHorizontalBox();
        box.add(Box.createHorizontalGlue());
        JButton btn = new JButton("Close");
        btn.addActionListener(
          new ActionListener()
            public void actionPerformed(ActionEvent evt)
              System.exit(0);
        box.add(btn);
        frame.add(box, BorderLayout.SOUTH);
        frame.setSize(400, 150);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      private static Icon removeIcon = UIManager.getIcon(
          "InternalFrame.paletteCloseIcon");
      private static Insets zeroInsets = new Insets(0,0,0,0);
      static Tab makeTab(String label, String text)
        JTextArea content = new JTextArea(text);
        final TitledTab tab = new TitledTab(label, null, content, null);
        // This is all you have to do to add a "remove" button to a tab
        JButton b = new JButton(removeIcon);
        b.setMargin(zeroInsets);
        b.addActionListener(
          new ActionListener()
            public void actionPerformed(ActionEvent evt)
              tab.getTabbedPanel().removeTab(tab);
        b.setFocusable(false);
        tab.setTitleComponent(b);
        return tab;
    }

Maybe you are looking for

  • Power supply dead? Can I get at the Hard drive?

    I recently had a storm which blew one of my external firewire drives (it goes on but won't mount) and when I tried using my older G4 (Quicksilver, with OS10.3.9, and Classic) to boot up in OS9 and try my Norton Utilities, the G4 froze. It did it seve

  • Using multiple ipods on a single itunes

    I currently have a 40GB ipod and have bought for my wife and daughter 2 2gb ipod nanos'. i have all our music on itunes in one library, how can i download only the songs my wife or daughter want onto their ipods as opposed to downloading every item w

  • While scheduling Error message

    Hi,Friends, While scheduling my maintenance plan its displaying warning like this: "Error calculating cost do you still want to save? How to resolve this.I hope you will help in this regard Regards, K.Sunil

  • No recognition and wont charge

    there is now no recognition of the ipod on my computer and it cant charge it, it seems frozen on the battery screen with the battery which normally moves up and down stuck half way across then goes onto the apple logo and the sad ipod face (continuou

  • Why won't Elements 6 open RAW files

       I just purchased a new Canon 50D camera and 6 won't open my RAW files.   Been working fine with my old Canon Rebel.  Can't find any update.  Do I need to get Elements 8????