11 Replies Latest reply on Oct 9, 2010 10:53 AM by viklund_anders

    JTabbedPane title alignment

    viklund_anders
      Hi,

      I need guidance how to align the tab title text
      "Right" title - right alignment
      "Left" title -left alignment

      Thanks!
      import java.awt.BorderLayout;
      
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JTabbedPane;
      
      public class MainClass {
        static void addIt(JTabbedPane tabbedPane, String text) {
          JLabel label = new JLabel(text);
          JButton button = new JButton(text);
          JPanel panel = new JPanel();
          tabbedPane.addTab(text, panel);
        }
      
        public static void main(String[] args) {
          JFrame f = new JFrame("JTabbedPane Sample");
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JTabbedPane tabbedPane = new JTabbedPane( JTabbedPane.LEFT);
          addIt(tabbedPane, "Tab One long title");
          addIt(tabbedPane, "Right"); //why is this title centered?
          addIt(tabbedPane, "Left");  //why is this title centered?
          f.add(tabbedPane);
          f.setSize(300, 200);
          f.setVisible(true);
        }
      }
      Edited by: user6102378 on 2010-okt-07 10:04
        • 1. Re: JTabbedPane title alignment
          796367
          Do you mean <tt>JTabbedPane.setTabPlacement()</tt>?

          http://java.sun.com/docs/books/tutorial/uiswing/components/tabbedpane.html

          P.S. Don't forget to add the JLabel and JButton to the JPanel before adding to JTabbedPane.
          • 2. Re: JTabbedPane title alignment
            viklund_anders
            The text on the tab title is for some reason centered.

            I would like to align the title text to the left and the close tab button to the right.

            It looks much better if the tab is moved/resized.

            Please note, the close tab button is not included in this small code sample.
            • 3. Re: JTabbedPane title alignment
              viklund_anders
              No ideas how to solve this problem?
              • 4. Re: JTabbedPane title alignment
                camickr
                The text is painted as part of the UI, which means it may be different for every LAF.

                If you want to customize this then you will need to create a custom UI. For example you might extend the MetalTabbedPaneUI to do this. I would guess you need to customize the paintText(...) method. Then after you create your component you would do:
                tabbedPane.setUI( new MyTabbedPaneUI() );
                • 5. Re: JTabbedPane title alignment
                  splungebob
                  According to this: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4220177, it's a bug that should've been fixed with the addition of using your own components for tab labels. However, I tried a quick demo using left-aligned JLabels, but the labels themselves were centered, since SwingUtilities.CENTER is a hard-coded value in the BasicTabbedPaneUI's layoutLabel method. So in my opinion, it's still a bug.

                  As camickr pointed out, you can implement your own UI, overriding layoutLabel(...) to use SwingUtilities.LEFT when it calls SwingUtilities.layoutCompoundLabel(...). I tried this, but it looked funny. Perhaps some more tweaks are needed beyond this.

                  Alternatively, are you up for a total hack?

                  1) Find the max width needed based on all titles (I used the preferredSize().width of a JLabel). Then for each title,
                  2) Create a non-opaque JLabel with the title
                  3) Create a non-opaque JPanel, using GridBagConstaints. At (0,0) put the label, with a horizontal Fill. At (0,1) put a horizontal strut that has your max width found.
                  4) Use the panel for your tab label
                  import java.awt.*;
                  
                  import javax.swing.*;
                  import javax.swing.plaf.basic.*;
                  import javax.swing.text.*;
                  
                  public class TabbedPaneProblem
                  {
                    static int index = 0;
                    static int maxTitleWidth = 0;
                    
                    static void addIt(JTabbedPane pane, String text) {
                      JLabel label = new JLabel(text);
                      label.setOpaque(false);
                      
                      JButton button = new JButton(text);
                      JPanel panel = new JPanel();
                      panel.add(button);
                      pane.addTab("", panel);
                      
                     JPanel titlePanel = new JPanel(new GridBagLayout());;
                      GridBagConstraints gbc = new GridBagConstraints();
                      gbc.gridx = 0;
                      gbc.gridy = 0;
                      gbc.weightx = 1;
                      gbc.anchor = GridBagConstraints.WEST;
                      gbc.fill = GridBagConstraints.HORIZONTAL;
                      titlePanel.add(label, gbc);
                      
                      gbc.gridx = 0;
                      gbc.gridy = 1;
                      titlePanel.add(Box.createHorizontalStrut(maxTitleWidth), gbc);
                      titlePanel.setOpaque(false);    
                      pane.setTabComponentAt(index++, titlePanel);
                    }
                   
                    public static void main(String[] args)
                    {
                      JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
                      String[] titles = new String[]{"Very Very Long Title", "Normal Title", "Short"};
                      
                      for (String title : titles)
                      {
                        maxTitleWidth = Math.max(
                                new JLabel(title).getPreferredSize().width, maxTitleWidth);
                      }
                      
                      for (String title : titles)
                      {
                        addIt(tabbedPane, title);
                      }
                      
                      JFrame f = new JFrame("JTabbedPane Sample");
                      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      f.add(tabbedPane);
                      f.setSize(300, 200);
                      f.setVisible(true);
                    }
                  }
                  Edited by: splungebob on Oct 7, 2010 5:18 PM
                  • 6. Re: JTabbedPane title alignment
                    terai
                    or override the BasicTabbedPaneUI#layoutLabel(...) method:
                    import java.awt.*;
                    import javax.swing.*;
                    import javax.swing.plaf.metal.MetalTabbedPaneUI;
                    import javax.swing.text.View;
                    public class MainClass2 {
                      public JComponent makeUI() {
                        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
                        tabbedPane.setUI(new MyTabbedPaneUI());
                        tabbedPane.addTab("Tab One long title", new JLabel());
                        tabbedPane.addTab("Right", new JLabel());
                        tabbedPane.addTab("Left", new JLabel());
                        return tabbedPane;
                      }
                      public static void main(String[] args) {
                        EventQueue.invokeLater(new Runnable() {
                          @Override public void run() {
                            createAndShowGUI();
                          }
                        });
                      }
                      public static void createAndShowGUI() {
                        JFrame f = new JFrame();
                        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                        f.getContentPane().add(new MainClass2().makeUI());
                        f.setSize(320, 240);
                        f.setLocationRelativeTo(null);
                        f.setVisible(true);
                      }
                    }
                    class MyTabbedPaneUI extends MetalTabbedPaneUI {
                      @Override
                      protected void layoutLabel(int tabPlacement,
                                                 FontMetrics metrics, int tabIndex,
                                                 String title, Icon icon,
                                                 Rectangle tabRect, Rectangle iconRect,
                                                 Rectangle textRect, boolean isSelected ) {
                        textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
                        View v = getTextViewForTab(tabIndex);
                        if (v != null) {
                          tabPane.putClientProperty("html", v);
                        }
                        SwingUtilities.layoutCompoundLabel((JComponent) tabPane,
                                                           metrics, title, icon,
                                                           SwingUtilities.CENTER,
                                                           SwingUtilities.LEFT, //CENTER, <----
                                                           SwingUtilities.CENTER,
                                                           SwingUtilities.TRAILING,
                                                           tabRect,
                                                           iconRect,
                                                           textRect,
                                                           textIconGap);
                        tabPane.putClientProperty("html", null);
                        textRect.translate(tabInsets.left, 0); //<----
                        //textRect.width -= tabInsets.left+tabInsets.right;
                    
                        int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
                        int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
                        iconRect.x += xNudge;
                        iconRect.y += yNudge;
                        textRect.x += xNudge;
                        textRect.y += yNudge;
                      }
                    }
                    • 7. Re: JTabbedPane title alignment
                      kleopatra-JavaNet
                      splungebob wrote:
                      According to this: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4220177, it's a bug that should've been fixed with the addition of using your own components for tab labels. However, I tried a quick demo using left-aligned JLabels, but the labels themselves were centered, since SwingUtilities.CENTER is a hard-coded value in the BasicTabbedPaneUI's layoutLabel method. So in my opinion, it's still a bug.
                      incredible - but true :-(

                      BTW, for custom tab components, the centering isn't done in layoutLabel, but in the TabbedPaneLayoutManager's layoutTabContainer. For anybody being desparate enough, hooking into that manager might be an option (didn't try, though, probably much c&p needed)


                      >
                      As camickr pointed out, you can implement your own UI,
                      we all know, that out-in-the-wild that's rarely an option ;-) and lots of work to get really right.

                      >
                      Alternatively, are you up for a total hack?

                      1) Find the max width needed based on all titles (I used the preferredSize().width of a JLabel). Then for each title,
                      2) Create a non-opaque JLabel with the title
                      3) Create a non-opaque JPanel, using GridBagConstaints. At (0,0) put the label, with a horizontal Fill. At (0,1) put a horizontal strut that has your max width found.
                      4) Use the panel for your tab label
                      impressive try :-) fails for normal tabs (that on top) if there are more than one row of tabComponents.

                      No easy way out, IMO - except using a LAF which actively supports alternative alignments ;-)

                      CU
                      Jeanette
                      • 8. Re: JTabbedPane title alignment
                        viklund_anders
                        Hmm. I can't get it working with close button in my tab titles, its still centered.

                        This is what it looks like:
                        import java.awt.*;
                         
                        import javax.swing.*;
                        import javax.swing.plaf.basic.*;
                        import javax.swing.text.*;
                         
                        public class TabbedPaneProblem
                        {
                         static JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
                          public static void main(String[] args)
                          {
                            //JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
                            ButtonTabComponent longTitleComponent = new ButtonTabComponent("Very long title text here", tabbedPane)
                            ButtonTabComponent shortTitleComponent = new ButtonTabComponent("short title", tabbedPane)
                            
                            tabbedPane.add("Very long title text here",new JScrollPane())
                            tabbedPane.add("short title",new JScrollPane())
                            
                            tabbedPane.setTabComponentAt(0,longTitleComponent)
                            tabbedPane.setTabComponentAt(1,shortTitleComponent)
                            
                            JFrame f = new JFrame("JTabbedPane Sample");
                           // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                            f.add(tabbedPane);
                            f.setSize(300, 200);
                            f.setVisible(true);
                          }
                        }
                        
                        
                        
                        import javax.swing.*;
                        import javax.swing.plaf.basic.BasicButtonUI;
                        import java.awt.*;
                        import java.awt.event.*;
                        
                        public class ButtonTabComponent extends JPanel {
                            private final JTabbedPane pane;
                            public final JLabel label;
                            private final JButton button = new TabButton();
                            
                            public ButtonTabComponent(String title, JTabbedPane pane) {
                        
                                super(new GridBagLayout(),true)
                        
                                if (pane == null) {
                                    throw new NullPointerException("TabbedPane is null");
                                }
                                this.pane = pane;
                                
                                setOpaque(false);
                                
                                GridBagConstraints gbc = new GridBagConstraints();
                                gbc.gridx = 0;
                                gbc.gridy = 0;
                                gbc.weightx = 1;
                                gbc.anchor = GridBagConstraints.WEST;
                                gbc.fill = GridBagConstraints.HORIZONTAL;
                                
                                label = new JLabel(title);
                                
                                add(label,gbc);
                        
                                label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10    ));
                                
                                GridBagConstraints gbcb = new GridBagConstraints();
                                gbcb.gridx = 1;
                                gbcb.gridy = 0;
                                gbcb.weightx = 1;
                                gbcb.anchor = GridBagConstraints.EAST;
                                gbcb.fill = GridBagConstraints.HORIZONTAL;
                                
                                add(button,gbcb);
                                
                                setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
                            }
                        
                            private class TabButton extends JButton implements ActionListener {
                                public TabButton() {
                                    int size = 17;
                                    setPreferredSize(new Dimension(size, size));
                                    setToolTipText("close this tab");
                                    //Make the button looks the same for all Laf's
                                    setUI(new BasicButtonUI());
                                    //Make it transparent
                                    setContentAreaFilled(false);
                                    //No need to be focusable
                                    setFocusable(false);
                                    setBorder(BorderFactory.createEtchedBorder());
                                    setBorderPainted(false);
                                    //Making nice rollover effect
                                    //we use the same listener for all buttons
                                    addMouseListener(buttonMouseListener);
                                    setRolloverEnabled(true);
                                    //Close the proper tab by clicking the button
                                    addActionListener(this);            
                                }
                        
                                public void actionPerformed(ActionEvent e) {
                                    int i = pane.indexOfTabComponent(ButtonTabComponent.this);
                        
                                    if (i != -1&&TabbedPaneProblem.tabbedPane.getTabCount()>0) {
                                        pane.remove(i);
                                    }
                                }
                        
                                //we don't want to update UI for this button
                                public void updateUI() {
                                }
                        
                                //paint the cross
                                protected void paintComponent(Graphics g) {
                                    super.paintComponent(g);
                                    Graphics2D g2 = (Graphics2D) g;
                                    Stroke stroke = g2.getStroke();
                                    //shift the image for pressed buttons
                                    if (!getModel().isPressed()) {
                                        g2.translate(-1, -1);
                                    } 
                                    g2.setStroke(new BasicStroke(2));
                                    g.setColor(Color.BLACK);
                                    if (getModel().isRollover()) {
                                        g.setColor(Color.MAGENTA);
                                    }            
                                    int delta = 6;
                                    g.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
                                    g.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
                                    //leave the graphics unchanged
                                    if (!getModel().isPressed()) {
                                        g.translate(1, 1);
                                    }
                                    g2.setStroke(stroke);
                                }
                            }
                        
                            private final static MouseListener buttonMouseListener = new MouseAdapter() {
                                public void mouseEntered(MouseEvent e) {
                                    Component component = e.getComponent();
                                    if (component instanceof AbstractButton) {
                                        AbstractButton button = (AbstractButton) component;
                                        button.setBorderPainted(true);
                                    }
                                }
                        
                                public void mouseExited(MouseEvent e) {
                                    Component component = e.getComponent();
                                    if (component instanceof AbstractButton) {
                                        AbstractButton button = (AbstractButton) component;
                                        button.setBorderPainted(false);
                                    }
                                }
                            };
                        }
                        • 9. Re: JTabbedPane title alignment
                          terai
                          import java.awt.*;
                          import java.awt.event.*;
                          import javax.swing.*;
                          import javax.swing.plaf.InsetsUIResource;
                          public class TabbedPaneProblem2 {
                            private final int maxTitleWidth = 180; //XXX
                            public JComponent makeUI() {
                              UIManager.put("TabbedPane.tabInsets", new InsetsUIResource(1,8,2,1));
                              JTabbedPane tp = new JTabbedPane(JTabbedPane.LEFT) {
                                @Override public void doLayout() {
                                  int tabCount = getTabCount();
                                  for (int i=0; i<tabCount; i++) {
                                    JComponent l = (JComponent)getTabComponentAt(i);
                                    if (l!=null) l.setPreferredSize(
                                        new Dimension(maxTitleWidth, l.getPreferredSize().height));
                                  }
                                  super.doLayout();
                                }
                              };
                              tp.add("Very very long title text here",new JScrollPane());
                              tp.add("short title",new JScrollPane());
                              tp.setTabComponentAt(0,new ButtonTabComponent(tp));
                              tp.setTabComponentAt(1,new ButtonTabComponent(tp));
                              return tp;
                            }
                            public static void main(String[] args) {
                              EventQueue.invokeLater(new Runnable() {
                                @Override public void run() { createAndShowGUI(); }
                              });
                            }
                            public static void createAndShowGUI() {
                              JFrame f = new JFrame();
                              f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                              f.getContentPane().add(new TabbedPaneProblem2().makeUI());
                              f.setSize(320, 240);
                              f.setLocationRelativeTo(null);
                              f.setVisible(true);
                            }
                          }
                          //http://download.oracle.com/javase/tutorial/uiswing/examples/components/index.html
                          class ButtonTabComponent extends JPanel {
                            private final JTabbedPane tabbedPane;
                            public final JLabel label;
                            private final JButton button = new TabButton();
                            public ButtonTabComponent(JTabbedPane pane) {
                              super(new BorderLayout(0,0));
                              if (pane == null) {
                                throw new NullPointerException("TabbedPane is null");
                              }
                              this.tabbedPane = pane;
                              setOpaque(false);
                              label = new JLabel() {
                                @Override public String getText() {
                                  int i = tabbedPane.indexOfTabComponent(ButtonTabComponent.this);
                                  return (i!=-1)?tabbedPane.getTitleAt(i):null;
                                }
                              };
                              add(label);
                              label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
                              add(button, BorderLayout.EAST);
                              setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
                            }
                            private class TabButton extends JButton implements ActionListener {
                              public TabButton() {
                                int size = 17;
                                setPreferredSize(new Dimension(size, size));
                                setToolTipText("close this tab");
                                setUI(new javax.swing.plaf.basic.BasicButtonUI());
                                setContentAreaFilled(false);
                                setFocusable(false);
                                setBorder(BorderFactory.createEtchedBorder());
                                setBorderPainted(false);
                                addMouseListener(buttonMouseListener);
                                setRolloverEnabled(true);
                                addActionListener(this);
                              }
                              public void actionPerformed(ActionEvent e) {
                                int i = tabbedPane.indexOfTabComponent(ButtonTabComponent.this);
                                if (i!=-1 && tabbedPane.getTabCount()>0) {
                                  tabbedPane.remove(i);
                                }
                              }
                              public void updateUI() {}
                              protected void paintComponent(Graphics g) {
                                super.paintComponent(g);
                                Graphics2D g2 = (Graphics2D) g;
                                Stroke stroke = g2.getStroke();
                                if (!getModel().isPressed()) g2.translate(-1, -1);
                                g2.setStroke(new BasicStroke(2));
                                g.setColor(Color.BLACK);
                                if (getModel().isRollover()) g.setColor(Color.MAGENTA);
                                int delta = 6;
                                g.drawLine(delta,delta,getWidth()-delta-1,getHeight()-delta-1);
                                g.drawLine(getWidth()-delta-1,delta,delta,getHeight()-delta-1);
                                if (!getModel().isPressed()) g.translate(1, 1);
                                g2.setStroke(stroke);
                              }
                            }
                            private static MouseListener buttonMouseListener = new MouseAdapter() {
                              public void mouseEntered(MouseEvent e) {
                                Component component = e.getComponent();
                                if (component instanceof AbstractButton) {
                                  AbstractButton button = (AbstractButton) component;
                                  button.setBorderPainted(true);
                                }
                              }
                              public void mouseExited(MouseEvent e) {
                                Component component = e.getComponent();
                                if (component instanceof AbstractButton) {
                                  AbstractButton button = (AbstractButton) component;
                                  button.setBorderPainted(false);
                                }
                              }
                            };
                          }
                          • 10. Re: JTabbedPane title alignment
                            viklund_anders
                            This question may not belong in here, but I get no response from the groovy forum.

                            How come this line is failing in the code above?
                             int i = tabbedPane.indexOfTabComponent(ButtonTabComponent.this); //testtitle.groovy:52
                            ////////////////// OUTPUT ////////////////////////////////////////////


                            Exception in thread "AWT-EventQueue-0"
                            java.lang.NullPointerException
                                 at ButtonTabComponent$1.propertyMissing(testtitle.groovy)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                 at java.lang.reflect.Method.invoke(Method.java:597)
                                 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
                                 at groovy.lang.MetaClassImpl.invokeMissingProperty(MetaClassImpl.java:754)
                                 at groovy.lang.MetaClassImpl$11.getProperty(MetaClassImpl.java:1772)
                                 at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:84)
                                 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:241)
                                 at ButtonTabComponent$1.getText(testtitle.groovy:54)
                                 at javax.swing.plaf.basic.BasicLabelUI.installComponents(BasicLabelUI.java:331)
                                 at javax.swing.plaf.basic.BasicLabelUI.installUI(BasicLabelUI.java:308)
                                 at javax.swing.JComponent.setUI(JComponent.java:662)
                                 at javax.swing.JLabel.setUI(JLabel.java:242)
                                 at javax.swing.JLabel.updateUI(JLabel.java:256)
                                 at javax.swing.JLabel.<init>(JLabel.java:145)
                                 at javax.swing.JLabel.<init>(JLabel.java:216)
                                 at ButtonTabComponent$1.<init>(testtitle.groovy)
                                 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                                 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
                                 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                                 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
                                 at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
                                 at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:107)
                                 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52)
                                 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:192)
                                 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:200)
                                 at ButtonTabComponent.<init>(testtitle.groovy:52)
                                 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                                 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
                                 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                                 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
                                 at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
                                 at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:107)
                                 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52)
                                 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:192)
                                 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:200)
                                 at TabbedPaneProblem2.makeUI(testtitle.groovy:22)
                                 at TabbedPaneProblem2$makeUI.call(Unknown Source)
                                 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
                                 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
                                 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
                                 at TabbedPaneProblem2.createAndShowGUI(testtitle.groovy:34)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                 at java.lang.reflect.Method.invoke(Method.java:597)
                                 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
                                 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
                                 at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1302)
                                 at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:759)
                                 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:163)
                                 at TabbedPaneProblem2$2.methodMissing(testtitle.groovy)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                 at java.lang.reflect.Method.invoke(Method.java:597)
                                 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
                                 at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:813)
                                 at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1107)
                                 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1060)
                                 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
                                 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
                                 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
                                 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143)
                                 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:147)
                                 at TabbedPaneProblem2$2.run(testtitle.groovy:28)
                                 at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
                                 at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
                                 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
                                 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
                                 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
                                 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
                                 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
                                 at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

                            Edited by: user6102378 on 2010-okt-09 03:13

                            Edited by: user6102378 on 2010-okt-09 03:13
                            • 11. Re: JTabbedPane title alignment
                              viklund_anders
                              Also, if I change from
                               JTabbedPane tp = new JTabbedPane(JTabbedPane.LEFT) 
                              to
                              JTabbedPane tp = new JTabbedPane(JTabbedPane.TOP)
                              I can see that the title is still centered.. the text should be aligned to the left and the close button to the right.


                              Thanks for any further help!