JtabbedPane equally size tab width..

Hello,
I have a JTabbedPane with about 7 tabs, but the tab names are mostly short and the sum width of the tabs takes up about 80% of the TabbedPane.
I'd like for the tab widths to take up the entire 100% of the tabbedPane (just a pref.) It would be nice if I could set the min tab width to 1/7 tabbedPane width. How can I set the width of each tab??

this might start you off - needs lots of testing
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Testing extends JFrame
  JTabbedPane tp = new JTabbedPane();
  int tabPaneWidth;
  int tabCounter;
  public Testing()
    setLocation(300,100);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    for(int x = 0; x < 3; x++)
      JPanel p = new JPanel();
      p.setPreferredSize(new Dimension(600,400));
      tp.addTab(""+(++tabCounter),p);
    JButton btn = new JButton("Add Tab");
    JPanel p = new JPanel();
    p.add(btn);
    getContentPane().add(tp,BorderLayout.CENTER);
    getContentPane().add(p,BorderLayout.SOUTH);
    tabPaneWidth = tp.getPreferredSize().width;
    tp.setUI(new MyUI());
    setResizable(false);//otherwise needs a componentListener
    pack();
    btn.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
        tp.addTab(""+(++tabCounter),new JPanel());}});
  class MyUI extends javax.swing.plaf.basic.BasicTabbedPaneUI
    protected int calculateTabWidth(int tabPlacement,int tabIndex, FontMetrics metrics)
      Insets margin = getInsets();
      return (int)((tabPaneWidth - margin.left - margin.right)/tp.getTabCount());
  public static void main(String[] args){new Testing().setVisible(true);}
}

Similar Messages

  • JTabbedPane Tab Widths Screwy on Wrap

    I have a JTabbedPane that add tabs dynamically from queried database records. Everything works great until the tabs wrap. Then, I get two or three tabs on the top row which are VERY wide and the bottom row will have the remaining tabs (about 8 at this point) that are normal size. The labels for the tabs aren't that much different in width. The tabs on the top row just seem to pad out unproportionally.
    I tried calling a custom TabbedPaneUI with a calculated width, and it still behaves the same. Has anyone run across this before? I'm not sure if it's something that can be managed with the UI, or if it's a layout issue. I'm loading JPanels with FlowLayout into the tabs and adding the tab pane to the top-level JFrame container. Thanks!

    I have the tab placement user settable now. It can be switched to JTabbedPane.RIGHT within the app. Also have a setting to use the SCROLL_TAB_LAYOUT policy instead of wrap. Maybe that will suffice. Just really weird the way the tabs are expanding on the first row. Anyway, thanks for your reply, bbritta. Five duke ducats deposited to your account. The remaining five available for a solution.
    To take a look at a jpeg of what I'm getting:
    http://www.catpoll.com/tabpane.jpg
    Cheers!!

  • 24pt Font Size Tab Text for JTabbedPane

    I'm creating an app for use with Touchscreens and need to make the buttons and such, large enough to fit the tip of a finger.
    I'm having trouble with the JTabbedPane font size and am having trouble finding a way to make the text in the tab larger.
    Same issue with text in a border. Just for looks but would be nice.
    And the text in the window title.
    I've searched the forums and the tutorials but couldn't find anything. Thanks in advance for your assistance.
    Stone

    Hi,
    the text in the window's title is managed by the underlying OS. So, I guess there is no possibility to influence this text. Except you change the display properties of the OS on this computer that runs your app.
    Regards,
    Patrick

  • Make firefox tabs auto-size similar to chrome rather than having the tab navigator arrows when the tab width is full???

    I want the tabs to auto-size/shrink when the tab bar width is full as opposed to adding the annoying extra step of navigation arrows...
    any suggestions?

    Suggestion:<br /> https://addons.mozilla.org/en-US/firefox/addon/custom-tab-width/

  • JTabbedPane: Tab Text, Tab Width and Tab Height

    Whenever i put text on JTabbedPane tab it displays it in one line, so when i have a text e.g. "XXXXXXXXX XXXXXXXXX"
    it displays it as it is not like XXXXXXXXX
    XXXXXXXXX
    How can I display it in two line or more?
    Does Tab width and height automatically adjust itself relative to the text inside it? If not how can I set the tab width and height?
    Thanks in advance.

    leemax quote:
    Simply add the escaped new line character "\n" to display the text of the tab on the next line.
    --Yeah i tried that already but anyway i solved the problem by making used of htnl tags "<br>"                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Setting tab width in JTabbedPane....

    hi all,
    I want to set the tab width to a constant value for all tabs in tabbed pane. How can i do this?
    Actually i have a tabbed pane where it has different length of strring to display in each tab. To make it uniform i want to set a constant width to the tab.
    please help...
    -Soni

    hi all
    i got it by overridding BasicTabbedPaneUI .
    class TabbedPaneUI extends BasicTabbedPaneUI {
    protected int calculateTabWidth(int tabPlacement, int tabIndex,
                                  FontMetrics metrics) {
              return TAB_TEXT_WIDTH;
    Now my problem is,
    all text in tab are center aligned.
    how to make it left aligned?
    please help....
    -Soni

  • Make CardLayout/JTabbedPane the size of the current card/pane?

    Hi all,
    I have a set of panels that a user flips through, which I can implement either as a set of JPanels in a CardLayout or as a JTabbedPane with the tabs hidden -- it's no difference to me.
    If all the panels have been instantiated, the current panel is always the size of the largest panel in the set. So if the current panel is significantly smaller than the largest panel, there's a bunch of unnecessary white space.
    Is there any way to set things up so that the the currently visible panel is always that size that it would normally want to be (i.e. if it weren'tpart of a CardLayout/JTabbedPane)?
    Thanks!
    Sam
    Below is a self-contained example using a JTabbedPane, but the same applies to a JPanel with CardLayout.
    import java.awt.*;
    import javax.swing.*;
    public class SwingTester extends JFrame{
         public SwingTester(){
              JTabbedPane tabbedPane = new JTabbedPane();
              JComponent smallComponent = new JLabel("Test");
              tabbedPane.addTab("Small tab", smallComponent);
              JComponent largeComponent = new JLabel("Test ... Test ... Test");
              largeComponent.setBorder(BorderFactory.createLineBorder(Color.RED, 20));
              tabbedPane.addTab("Large tab", largeComponent);
              getContentPane().add(tabbedPane);
         public static void main(String[] args){
              SwingTester st = new SwingTester();
              st.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              st.pack();
              st.setVisible(true);
    }

    I think that you'll need to do more than revalidate and / or repaint. You'll need to repack the JFrame:
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    class BigSmallPanels extends JPanel
        private static final String SMALL_PANEL = "Small Panel";
        private static final String LARGE_PANEL = "Large Panel";
        private JPanel smallPanel;
        private JPanel largePanel;
        BigSmallPanels(JFrame frame)
            setLayout(new BorderLayout(5, 5));
            setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
            smallPanel = createSmallPanel();
            largePanel = createLargePanel();
            add(largePanel, BorderLayout.CENTER);
            JPanel buttonPanel = new JPanel();
            JButton swapButton = new JButton(SMALL_PANEL);
            buttonPanel.add(swapButton);
            add(buttonPanel, BorderLayout.PAGE_END);
            swapButton.addActionListener(new SwapButtonListener(this, frame));
        private class SwapButtonListener implements ActionListener
            private JPanel panel = null;
            private JFrame frame = null;
            SwapButtonListener(JPanel panel, JFrame frame)
                this.panel = panel;
                this.frame = frame;
            public void actionPerformed(ActionEvent e)
                String command = e.getActionCommand();
                if (command.equals(SMALL_PANEL))
                    ((JButton)e.getSource()).setText(LARGE_PANEL);
                    ((JButton)e.getSource()).setActionCommand(LARGE_PANEL);
                    panel.remove(largePanel);
                    panel.add(smallPanel, BorderLayout.CENTER);
                    frame.pack();
                    //panel.revalidate();
                    //panel.repaint();
                else if (command.equals(LARGE_PANEL))
                    ((JButton)e.getSource()).setText(SMALL_PANEL);
                    ((JButton)e.getSource()).setActionCommand(SMALL_PANEL);
                    panel.remove(smallPanel);
                    panel.add(largePanel, BorderLayout.CENTER);
                    frame.pack();
                    //panel.revalidate();
                    //panel.repaint();
        private JPanel createSmallPanel()
            JPanel p = new JPanel();
            p.add(new JLabel("Small"));
            return p;
        private JPanel createLargePanel()
            JPanel p = new JPanel(new GridLayout(4, 4, 5, 5));
            for (int i = 0; i < 4; i++)
                for (int j = 0; j < 4; j++)
                    JLabel largeLabel = new JLabel("Large");
                    largeLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
                    p.add(largeLabel);
            return p;
        private static void createAndShowGUI()
            JFrame frame = new JFrame("BigSmallPanels Application");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(new BigSmallPanels(frame));
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
    }

  • Setting tab width for Text editor

    Simple ? I was unable to see this in the tool help. How do we set the tab width in the Text Editor for solaris.

    Hi,
    Please see the man page of xview.
    The parameter: text.tabWidth in the .Xdefaults file controls the tab width size.

  • Is there a way to set min and max tab widths in firefox 17 or 18?

    The browser tab width maximum and minimum options are no longer in about:config and the "tab width clip" has no effect on tab width in firefox 17 or 18.

    hello, the browser.tabs.tabClipWidth setting does only specify beyond which width a close button is shown on the tab. in order to set a custom tab size you can use this extension: https://addons.mozilla.org/firefox/addon/custom-tab-width/

  • Dynamic Tab Width ?

    Does anyone know how to make the tabwidth automatically adjust depending on the size of the browser?  (Just like this site http://www.picnik.com/app)
    thanks for your help

    I observed picnik.com ,th website is having flex/flash component which  uses 100% of width of browser .so in order to dynamically changing the width of Tab you need to capture resize (mx.events.ResizeEvent)  event of application component  (mx.core.Application)  and inside that method change the tab width accordingly .
    If this post help you to resolve your question .Please mark as "correct" or "helpful"
    Thanks
    Rushit Patel

  • After Leopard install I have 2 volumes of equal size

    After Leopard install I have 2 volumes of equal size. One has Leopard and the other has Tiger. How can I delete, remove, or get rid of the volume with Tiger on it? As I have upgraded to Leopard how can tell which one I have, i.e., 10.5 or 10.5.X?
    Thanks for your help.

    For some reason the Leopard installer kept your old Tiger partition instead of deleting it. It's probably your fault, but that doesn't matter...
    Before you do this, back up any data you still want from the Tiger partition. Also rename it to something that will differentiate it from your other volume(s?). Also back up your Leopard partition before any of this.
    Take your Leopard install disk, pop it in, reboot while holding C (or just click Install Leopard), choose a language, then from the menubar click Utilities, then Disk Utility. Once there, click your hard drive (not your Leopard or Tiger volumes) in the sidebar, go to the Partition tab on the right, click your Tiger volume's square (NOT YOUR LEOPARD VOLUME!!!), click the minus sign under that little graph, and click Partition. Then once that's done, drag the little resize line thingy on the bottom-left of your Leopard volume's square so that it fills up the entire area there.
    If you can't make the Leopard volume take up the entire drive, you'll have to wipe the entire hard drive and restore from a backup. Yes, you will have to unless you're okay with having less space then you can. (Why can't GParted resize HFS+?!?! WHY?!!?!?!!??!)

  • JTabbedPane MouseListener on tabs

    I want to add a MouseListener to a JTabbedPane, but not on the content JPanel, but on the right of the tabs.
    (see this image: http://yfrog.com/aijtabbedpaneg , the arrows mark where I want the mouse to be clicked when the listener acts)
    How can I do this?
    A simple tabbedpane.addMouseListener doesn't work and I can't find the tabs component where I can add the listener.

    Here's my attempt.
    import java.awt.Dimension;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTabbedPane;
    import javax.swing.SwingUtilities;
    public class TabbedPaneTest {
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test");
                    frame.setBounds(20, 20, 300, 300);
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    JTabbedPane tabs = new JTabbedPane();
                    Dimension size = new Dimension(100, 200);
                    JLabel label = new JLabel("Label 1");
                    JLabel otherLabel = new JLabel("Label 2");
                    label.setPreferredSize(size);
                    otherLabel.setPreferredSize(size);
                    tabs.add("Tab 1", label);
                    tabs.add("Tab 2", otherLabel);
                    tabs.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent e) {
                            JTabbedPane tabs = (JTabbedPane)e.getSource();
                            //Check that click was on tabbed pane itself an that there is no tab at that location.
                            System.out.println(tabs.findComponentAt(e.getX(), e.getY()) == tabs && tabs.indexAtLocation(e.getX(), e.getY()) == -1 ? "No tab at location." : "Tab at location.");
                    frame.add(tabs);
                    frame.setVisible(true);
    }

  • How to Re org the SQL 2008 database to have equal size data files

    Hello everyone -
    I have I/O issue with our production system (SAP ECC 6.0 on Windows 2008 and MSSQL 2008).
    Following are my I/0 stats in DB02 (since DB Start)
    ECPDATA1     E:     Data       25.779     28.053     4.689     1,056.68     36.297     23.326     2.515     45.301     14.43
    ECPDATA2     E:     Data       23.143     24.979     4.68     593.297     17.971     12.448     1.238     47.663     14.518
    ECPDATA3     G:     Data   9.17     9.807     3.477     1,018.69     36.144     21.938     2.457     46.434     14.712
    ECPDATA4     F:     Data  10.985     11.788     2.69     148.512     4.777     3.248     0.314     45.722     15.201
    ECPDATA5     F:     Data       14.746     16.164     2.676     162.39     6.693     3.679     0.432     44.139     15.491
    ECPLOG1      D:     Log        5.337     27.081     4.916     26.962     26.264     0.037     1.919     726.928     13.688
    ECPLOG2      F:     Log     0.755     17.582     0.487     35.472     35.161     0.042     2.637     845.998     13.334
    The fourth column is ms/op which is very high and also asymmetrical for all the data files.
    Also, The data files are not of equal size
    ECPDATA1     106,173
    ECPDATA2     59,588
    ECPDATA3     105,036
    ECPDATA4     14,992
    ECPDATA5     16,491
    ECPLOG1       1,025
    ECPLOG2             3,199
    So ECPdata1 and ECPdata3 are about 105 GB while #4 and #5 are 14 GB and 16 GB each. As per SQL best practices, all the Data files should be of equal size to get the best performance.
    How do I make the data files with equal sizes ?
    Your help is very much appreciated.
    Thank you
    -TSB

    Hi dudes!
    The key here is that you manually grow your datafiles before the autogrown mechanism comes to play; in fact, SAP recommends setting the autogrow just to avoid the hypothetical case that should never arrive in which the DB administrator forgot about the database size and it ran out of space.
    Otherwise, if you properly monitor and manage your DB you should always grant that at least 30% (to say) of free space is allocated in your datafiles. If you do so, the SQL Server engine should do the rest, as it follows a proportional filling strategy as you can read in SAP note 1238993.
    In case your database is not still proportional, my advise is that you just manually grow the datafiles so that all them are the same size, and so SQL Server will do the rest. If you however need to addresss that immediately, you will need to reorganize your database, which is not just more sensitive and complicate, but also which involves some I/O intensive operations (check SAP note 159316).
    Cheers!!
    --Jesú

  • Jtabbedpane with replacing tab content

    Hello,
    I am developing an applet that should contain a JTabbedPane with 2 tabs.
    The second tab is easy to do because ti contains one Jpanel all the way.
    the first however is an issue, because i am supposed to change its content when the applet is running.
    this means i have 3 JPanels, J1, J2, J3.
    At tge beginning the applet contains J1 in the first tab.
    and J1 contains a button. when i click that button the applet should replace J1 with J2.
    the problem is i haven't managed to find a solution yet :(
    I have tried with setvisible(false) and validate(). It won't work. I also tried to add the J2 panel over J1, but encountered no succes.
    anybody has any idea ?
    Message was edited by:
    asrfel

    If you want to change back and forth repeatedly then wrap J1/2/3 in a JPanel with a CardLayout.
    If you can discard one when it's done with, use the remove() and insertTab() methods of JTabbedPane.

  • The Custom Tab Width add-on doesn't work in Firefox 25

    I use the add-on 'Custom Tab Width' (https://addons.mozilla.org/en-US/firefox/addon/custom-tab-width) so that my tabs can shrink infinitely, but after updating to Firefox 25, it no longer seems to work. Is this add-on incompatible with Firefox 25? In that case, is there any other way to make the tabs shrink infinitely?

    Hi GAPa,
    Thanks for visiting Mozilla Support!
    This addon is indeed compatible with Fx25 as I have tested it. Try this. Press '''CTRL + SHIFT +A''' and click on '''Extensions''', then go into Options on '''Custom Tab Width''' then input '''1''' as MIN. Does that help?
    If not, feel free to reply and we will try other things to get this resolved.

Maybe you are looking for

  • Preview in Web Browser stopped working

    Hello - I used to be able to preview my project in Web Browser but today for some reason after I click it, the window opens and it looks like it is generating but when it finishes the browser window does not open.  I can preview Project, Preview from

  • Maximum Number of Pages in PDFs

    Does anyone know if there is a maximum number of pages that can be contained in a PDF document?  Or is it more a question of file size limitation?

  • What causes lines in photos?

    When I open photos in Elements 9 random lines appear in image. Lines are not in original images in Nikon software so the problem has to be with Elements. I've uninstalled and reinstalled without any change. Any Ideas?

  • Voting Thread for the SAP NetWeaver ABAP Developer Edition for Linux

    Hi Everyone, as Mario Herger suggested in the discussion to his Blog [New Community Developer License is available|/people/mario.herger/blog/2010/01/20/new-community-developer-license-is-available] I start the topic requesting a SAP NetWeaver ABAP De

  • Existing video files won't import into Lightroom 4.1

    I have several hundred videos I have taken, either with a Canon SD800, Canon S95, Canon T2i or a GoPro. New videos I take on this equipment works just fine when adding to Lightroom. But when I try to import older files, I get error: video file not im