Bug: JTabbedPane setTabLayoutPolicy in 1.4

I noticed weird behavior when using setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT). When adding a MouseListener to a JTabbedPane with this property set (it's a recent addition since 1.4), mouseClicked, mouseReleased, and mousePressed events do not occur. These events don't occur when clicked on the tab name (it works in other various areas though), but this is not standard behavior. When adding a MouseListener to a JTabbedPane, these events should occur no matter where you clicked on the JTabbedPane. Expected results are received with the default value, setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT). Here's someone else (the only other person I know) who experienced this problem:
http://forum.java.sun.com/thread.jsp?forum=57&thread=185937
Try running his code (my code is too long to show, it's part of a big project) and let me know if this bug exists for whatever operating system you use. Could anyone let me know if there's a workaround for this problem? I filed this bug and I hope Sun will fix it soon :) Thanks.

I dunno whether its a bug or not but in my old application Tab key stopped working when run on JRE1.4.1!
And if I had Java Console open Tab worked fine (earlier we were using JRE1.3 plugin, now I tried the application on JRE1.4.1 ).
Only after setting the myApplet.FocusCycleRoot(true) did it started working again.
Cheers,
Amit

Similar Messages

  • Help with calling up a JPanel

    I posted a simular problem to this earlier, but got tottally muddled up in what i was writing. I have been stuck on this now for quite a while and its problably really straight forward. Basically i have a class called Meet which extends a JPanel as it is using JTabbedPane and i followed a sun tutorial. Now this JPanel gets added to a JFrame in my code through
           JFrame frame = new JFrame("MEET_dataTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new Meet(), BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);Now this class all works great when run alone. But then in another class which extends a JFrame, one of the buttons should be calling up the above Meet class. So i declared Meet meet; and i created the CreateAtlDatabase_actionPerformed method.
         private void CreateAtlDatabase_actionPerformed()
              meet = new Meet();
                    this.dispose();
              } But everytime this button is pressed, the whole program crashes. I have also tried different ways, for instance i removed the JFrame code from my Meet class and placed it in my CreateAtlDatabase_actionPerformed method, so that the frame is created on request, but then i have problems disposing of the gui in my Meet class. The circle continues. Any advise on what i can do would be great.

    But everytime this button is pressed, the whole program crashes.By this i mean when i press the button, the whole application just freezes, and then after quite a long time my command line displays
    Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap spa
    ce
            at javax.swing.plaf.basic.BasicTabbedPaneUI.createScrollButton(BasicTabb
    edPaneUI.java:305)
            at javax.swing.plaf.basic.BasicTabbedPaneUI$ScrollableTabSupport.createB
    uttons(BasicTabbedPaneUI.java:3253)
            at javax.swing.plaf.basic.BasicTabbedPaneUI$ScrollableTabSupport.<init>(
    BasicTabbedPaneUI.java:3238)
            at javax.swing.plaf.basic.BasicTabbedPaneUI.installComponents(BasicTabbe
    dPaneUI.java:258)
            at javax.swing.plaf.basic.BasicTabbedPaneUI.installUI(BasicTabbedPaneUI.
    java:206)
            at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.propertyChange(Basic
    TabbedPaneUI.java:3521)
            at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSup
    port.java:339)
            at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSup
    port.java:276)
            at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSup
    port.java:297)
            at java.awt.Component.firePropertyChange(Component.java:7908)
            at javax.swing.JComponent.firePropertyChange(JComponent.java:4454)
            at javax.swing.JTabbedPane.setTabLayoutPolicy(JTabbedPane.java:536)
            at Meet.<init>(Meet.java:264)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)I then took this code out of my Meet class(class which extends the JPanel)
            JFrame frame = new JFrame("MEET_dataTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new Meet(), BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);And i place it in the action event of the class that calls up the JPanel.
         private void CreateAtlDatabase_actionPerformed()
            JFrame frame = new JFrame("MEET_dataTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new Meet(), BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);
            this.dispose();
              } Now that seems to do the trick, i just wasnt sure if it was allowed. But in doing this another problem is created. In my Meet class, i have a go back button which should return the user to the JFrame gui and dispose of the JPanel gui. But of course you cannot use this.dispose() on a JPanel and i no longer have the JFrame to which the panel is added in this class, which means i cant dispose of its JFrame. I have tried using System.exit(0) but this closes everything, and my last attempt has been
    private void back_actionPerformed() 
            this.getParent().setVisible(false);
            CreateAtlDatabase data = new CreateAtlDatabase();
      Which removes the JPanel but leaves an empty JFrame. Now this is where i am stuck, how can i dispose of this? and of course is the moving of my JFrame to my other class ok?
    cheers

  • Tab of JTabbedPane bug perhaps?

    I've noticed many instances of JTabbedPane not setting current selected
    tabs to a specified color. I find this kind of strange since it seems
    like it's the other way around on my Solaris as well as my HP-UX box.
    What I'm wondering is if this is a new bug that got introduced by an
    attempt to "fix" the original bug where the selected tab is not taking
    the new color? If so, what's the workaround to getting the unselected
    tabs to respect the new color that one wishes to invoke?
    I've tried a myriad of techniques to get this unselected tab color to
    change to the color I wished for it to be, but to my dismay it always
    stay a Color.darkGray color. I was successful in changing the background
    of the selected, but not the unselected tabs.
    I've used UIManager and my own customized LookAndFeel manipulator to
    get the other stuff to work, except for this annoying "bug" it seems.
    Please help..
    Thanks in advance..

    Well.. I've been doing that and nothing seems to budge..
    Not sure exactly why it seems like whatever is done whether
    it be through the custom L&F or through custom subclass of
    JTabbedPane that forcibly/manually alter the color properties,
    nothing happens.
    So, to me, it just feels like an internal JVM bug.

  • JD3 vs JD2 - jTabbedPane bug?

    In a JD3 applet, after placing several infobus components on each of several jTabbedPane jPanels, the applet runs in neither the appletviewer nor when deployed. However, when the applet is run in the appletviewer, it can be seen if you select the "restart" item in the pull-down menu of the appletviewer.
    When the components are placed on only the first of the jPanels, the applet does run correctly in the appletviewer and also when deployed. However, if after placing components on more than one JPanel, you remove the components from all but the first jPanel, the problem persists.
    The problem described above does not exist in JD2.

    The following problem applies to JD3 but not JD2, where things work correctly.
    The code below produces an applet with three tabs. Each tab has one or more components on it. If you drag and drop (reposition) the components on the second or third tab, the applet can neither be seen in the appletviewer nor deployed. You can reposition the components programatically, but this is impractical for the case where a few hundred components are involved.
    Is there a way to drag and drop components on these tabs without "breaking" the application?
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import oracle.jdeveloper.layout.*;
    public class Applet1 extends JApplet {
    boolean isStandalone = false;
    JPanel jPanel1 = new JPanel();
    JTabbedPane jTabbedPane1 = new JTabbedPane();
    JPanel jPanel2 = new JPanel();
    JPanel jPanel3 = new JPanel();
    JPanel jPanel4 = new JPanel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    XYLayout xYLayout1 = new XYLayout();
    JTextField jTextField1 = new JTextField();
    JTextField jTextField2 = new JTextField();
    //Get a parameter value
    public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
    (getParameter(key) != null ? getParameter(key) : def);
    //Construct the applet
    public Applet1() {
    //Initialize the applet
    public void init() {
    try {
    jbInit();
    catch (Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    this.setSize(400,300);
    jPanel1.setLayout(null);
    jTabbedPane1.setBounds(new Rectangle(49, 5, 303, 274));
    jPanel4.setLayout(xYLayout1);
    jPanel3.setLayout(xYLayout1);
    jPanel2.setLayout(xYLayout1);
    jButton1.setText("jButton1");
    jButton2.setText("jButton2");
    jButton3.setText("jButton3");
    jTextField1.setText("jTextField1");
    jTextField2.setText("jTextField2");
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jTabbedPane1, null);
    jTabbedPane1.addTab("Pane 0", jPanel4);
    jPanel4.add(jButton3,new XYConstraints(126, 57, -1, -1));
    jPanel4.add(jTextField1, new XYConstraints(73, 143, 102, 23));
    jTabbedPane1.addTab("Pane 1", jPanel3);
    jPanel3.add(jButton1, new XYConstraints(126, 57, -1, -1));
    jPanel3.add(jTextField2,new XYConstraints(59, 140, 90, 23));
    jTabbedPane1.addTab("Pane 2", jPanel2);
    jPanel2.add(jButton2, new XYConstraints(126, 57, -1, -1));
    //Get Applet information
    public String getAppletInfo() {
    return "Applet Information";
    //Get parameter info
    public String[][] getParameterInfo() {
    return null;
    null

  • Color behind the tabbs of JTabbedPane in SCROLL layout

    Hi all, This is a repost as no one gave me a solution for this problem.
    When SCROLL_TAB_LAYOUT is specified, the color behind the tabbs is not the color of its container. With WRAP layout, the color behind the tabbs is the color of its container.
    Is this a bug? or am I doing wrong?
    If one can execute this code, it would be clear of what I am talking about. Just comment out the tabbPane.setTabLayoutPolicy line and run it again to see the actual behaviour.
    JTabbedPane tabbPane = new JTabbedPane();
    tabbPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    tabbPane.setBackground(Color.white);
    tabbPane.add("one",new JPanel());
    tabbPane.add("two",new JPanel());
    JPanel parentPanel = new JPanel(new BorderLayout());
    parentPanel.setBackground(Color.red); // the color i want to be appeared as the background for tabbed pane and not for tabbs.
    parentPanel.add(tabbPane,BorderLayout.CENTER);
    JFrame jf = new JFrame();
    jf.getContentPane().add(parentPanel);
    jf.pack();
    jf.setVisible(true);
    Thanks in advance.

    Maybe this:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4690946
    Bug ID:      4690946
    Votes      6
    Synopsis      REGRESSION: JTabbedPane.setBackground() and setOpaque() have no effect
    Category      java:classes_swing
    Reported Against      1.4
    Release Fixed      1.5(tiger)
    State      Closed, fixed

  • JTabbedPane Background Color incorrect when using SCROLL_TAB_LAYOUT

    I am tring to set the background (JDK 1.41_02) on a JTabbedPane that uses SCROLL_TAB_LAYOUT. It is reported as a bug with this example:-
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    public class TestFrame extends JFrame {
    JSplitPane jSplitPane1 = new JSplitPane();
    JTabbedPane jTabbedPane2 = null;
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JPanel jPanel4 = new JPanel();
    JPanel jPanel3 = new JPanel();
    JTabbedPane jTabbedPane1 = null;//new JTabbedPane();
    public TestFrame() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {
    TestFrame untitled11 = new TestFrame();
    untitled11.setSize(250,250);
    untitled11.show();
    private void jbInit() throws Exception {
    jTabbedPane1 = new JTabbedPane();
    jTabbedPane2 = new JTabbedPane();
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
    jTabbedPane1.setBackground(Color.red);
    // jTabbedPane1.setOpaque(false);
    jTabbedPane1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    jTabbedPane1.add(jPanel3, "Problem");
    jTabbedPane1.add(jPanel4, "Pane");
    jTabbedPane2.setBackground(Color.orange);
    jTabbedPane2.setOpaque(true);
    jTabbedPane2.add(jPanel1, "Working");
    jTabbedPane2.add(jPanel2, "Pane");
    jSplitPane1.add(jTabbedPane1, JSplitPane.TOP);
    jSplitPane1.add(jTabbedPane2, JSplitPane.BOTTOM);
    jSplitPane1.setDividerLocation(100);
    this.getContentPane().add(jSplitPane1, BorderLayout.CENTER);
    I have tried added the suggested solution
    javax.swing.UIManager.put("TabbedPane.tabsOpaque", Boolean.FALSE);
    javax.swing.UIManager.put("TabbedPane.contentOpaque", Boolean.FALSE);
    prior to creating the tab pane but stll get the problem.
    am I doing something wrong.

    The fix for the bug 4690946(http://developer.java.sun.com/developer/bugParade/bugs/4690946.html) was integrated only in jdk 1.5

  • MouseListener in JTabbedPane jdk1.4

    Hi guys,
    I am trying to use JTabbedPane with jkd1.4. my problem is I am not able to detect mouse click if i use new feature of JTabbedPane.SCROLL_TAB_LAYOUT. because I thinkg it is already used for up and arrow. If i comment out that line form the following code mouse click works fine. Any way to have both the feature on .i.e. mouseclick detection and scrollable tabs.
    Thanks for help.
    import javax.swing.table.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    public class TabbedPaneDemo extends JPanel implements MouseListener {
    public TabbedPaneDemo() {
    ImageIcon icon = new ImageIcon("images/middle.gif");
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    tabbedPane.setTabPlacement(SwingConstants.LEFT);
    for(int i =0;i< 50;i++){
    tabbedPane.addTab( "panel " + i, icon, makeTextPanel("Blah blah blah " + i), "Still does nothing");
    // System.out.println(i);
         tabbedPane.addMouseListener(this);
    //Add the tabbed pane to this panel.
    setLayout(new GridLayout(1, 1));
    add(tabbedPane);
    public void mouseClicked(MouseEvent e){
         System.out.println("HI I AM IN MOUSE EVENT");
    public void mouseEntered(MouseEvent e){};
    public void mouseExited(MouseEvent e){};
    public void mousePressed(MouseEvent e){};
    public void mouseReleased(MouseEvent e){};
    protected Component makeTextPanel(String text) {
    JPanel panel = new JPanel(false);
    JLabel filler = new JLabel(text);
    filler.setHorizontalAlignment(JLabel.CENTER);
    panel.setLayout(new GridLayout(1, 1));
    panel.add(filler);
    return panel;
    public static void main(String[] args) {
    JFrame frame = new JFrame("TabbedPaneDemo");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}
    frame.getContentPane().add(new TabbedPaneDemo(),
    BorderLayout.CENTER);
    frame.setSize(800, 400);
    frame.setVisible(true);

    This is a known bug which is not going to be fixed until the 1.5 release:
    http://developer.java.sun.com/developer/bugParade/bugs/4465870.html

  • How can we prevent JTabbedPanes from transferring focus to components outside of the tabs during tab traversal?

    Hi,
    I noticed a strange focus traversal behavior of JTabbedPane.
    During tab traversal (when the user's intention is just to switch between tabs), the focus is transferred to a component outside of the tabs (if there is a component after/below the JTabbedPane component), if using Java 6. For example, if using the SSCCE below...
    import java.awt.BorderLayout;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class TabbedPaneTest extends JPanel {
        public TabbedPaneTest() {
            super(new BorderLayout());
            JTabbedPane tabbedPane = new JTabbedPane();
            tabbedPane.addTab("Tab 1", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
            tabbedPane.addTab("Tab 2", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
            tabbedPane.addTab("Tab 3", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
            tabbedPane.addTab("Tab 4", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(tabbedPane);
            JButton button = new JButton("Dummy component that gains focus when switching tabs");
            panel.add(button, BorderLayout.SOUTH);
             * To replicate the focus traversal issue, please follow these steps -
             * 1) Run this program in Java 6; and then
             * 2) Click on a child component inside any tab; and then
             * 3) Click on any other tab (or use the mnemonic keys ALT + 1 to ALT 4).
            button.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    System.err.println("Gained focus (not supposed to when just switching tabs).");
            add(new JScrollPane(panel));
        private JPanel buildPanelWithChildComponents() {
            JPanel panel = new JPanel();
            BoxLayout boxlayout = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
            panel.setLayout(boxlayout);
            panel.add(Box.createVerticalStrut(3));
            for (int i = 0; i < 4; i++) {
                panel.add(new JTextField(10));
                panel.add(Box.createVerticalStrut(3));
            return panel;
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test for Java 6");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new TabbedPaneTest());
                    frame.pack();
                    frame.setVisible(true);
    ... Then we can replicate this behavior by following these steps:
    1) Run the program in Java 6; and then
    2) Click on a child component in any of the tabs; and then
    3) Click on any other tab (or use the mnemonic keys 'ALT + 1' to 'ALT + 4').
    At step 3 (upon selecting any other tab), the focus would go to the component below the JTabbedPane first (hence the printed message in the console), before actually going to the selected tab.
    This does not occur in Java 7, so I'm assuming it is a bug that is fixed. And I know that Oracle suggests that we should use Java 7 nowadays.
    The problem is: We need to stick to Java 6 for a certain application. So I'm looking for a way to fix this issue for all our JTabbedPane components while using Java 6.
    So, is there a way to prevent JTabbedPanes from passing the focus to components outside of the tabs during tab traversal (e.g. when users are just switching between tabs), in Java 6?
    Note: I've read the release notes between Java 6u45 to Java 7u15, but I was unable to find any changes related to the JTabbedPane component. So any pointers on this would be deeply appreciated.
    Regards,
    James

    Hi Kleopatra,
    Thanks for the reply.
    Please allow me to clarify first: Actually the problem is not that the child components (inside tabs) get focused before the selected tab. The problem is: the component outside of the tabs gets focused before the selected tab. For example, the JButton in the SSCCE posted above gets focused when users switch between tabs, despite the fact that the JButton is not a child component of the JTabbedPane.
    It is important for me to prevent this behavior because it causes a usability issue for forms with 'auto-scrolling' features.
    What I mean by 'auto-scrolling' here is: a feature where the form automatically scrolls down to show the current focused component (if the component is not already visible). This is a usability improvement for long forms with scroll bars (which saves the users' effort of manually scrolling down just to see the focused component).
    To see this feature in action, please run the SSCCE below, and keep pressing the 'Tab' key (the scroll pane will follow the focused component automatically):
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.JViewport;
    import javax.swing.SwingUtilities;
    public class TabbedPaneAutoScrollTest extends JPanel {
        private AutoScrollFocusHandler autoScrollFocusHandler;
        public TabbedPaneAutoScrollTest() {
            super(new BorderLayout());
            autoScrollFocusHandler = new AutoScrollFocusHandler();
            JTabbedPane tabbedPane = new JTabbedPane();
            tabbedPane.addTab("Tab 1", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
            tabbedPane.addTab("Tab 2", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
            tabbedPane.addTab("Tab 3", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
            tabbedPane.addTab("Tab 4", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(tabbedPane);
            JButton button = new JButton("Dummy component that gains focus when switching tabs");
            panel.add(button, BorderLayout.SOUTH);
             * To replicate the focus traversal issue, please follow these steps -
             * 1) Run this program in Java 6; and then
             * 2) Click on a child component inside any tab; and then
             * 3) Click on any other tab (or use the mnemonic keys ALT + 1 to ALT 4).
            button.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    System.err.println("Gained focus (not supposed to when just switching tabs).");
            button.addFocusListener(autoScrollFocusHandler);
            JScrollPane scrollPane = new JScrollPane(panel);
            add(scrollPane);
            autoScrollFocusHandler.setScrollPane(scrollPane);
        private JPanel buildPanelWithChildComponents(int numberOfChildComponents) {
            final JPanel panel = new JPanel(new GridBagLayout());
            final String labelPrefix = "Dummy Field ";
            final Insets labelInsets = new Insets(5, 5, 5, 5);
            final Insets textFieldInsets = new Insets(5, 0, 5, 0);
            final GridBagConstraints gridBagConstraints = new GridBagConstraints();
            JTextField textField;
            for (int i = 0; i < numberOfChildComponents; i++) {
                gridBagConstraints.insets = labelInsets;
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = i;
                panel.add(new JLabel(labelPrefix + (i + 1)), gridBagConstraints);
                gridBagConstraints.insets = textFieldInsets;
                gridBagConstraints.gridx = 2;
                textField = new JTextField(22);
                panel.add(textField, gridBagConstraints);
                textField.addFocusListener(autoScrollFocusHandler);
            return panel;
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test for Java 6 with auto-scrolling");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new TabbedPaneAutoScrollTest());
                    frame.setSize(400, 300);
                    frame.setVisible(true);
    * Crude but simple example for auto-scrolling to focused components.
    * Note: We don't actually use FocusListeners for this feature,
    *       but this is short enough to demonstrate how it behaves.
    class AutoScrollFocusHandler extends FocusAdapter {
        private JViewport viewport;
        private JComponent view;
        public void setScrollPane(JScrollPane scrollPane) {
            viewport = scrollPane.getViewport();
            view = (JComponent) viewport.getView();
        @Override
        public void focusGained(FocusEvent event) {
            Component component = (Component) event.getSource();
            view.scrollRectToVisible(SwingUtilities.convertRectangle(component.getParent(),
                    component.getBounds(), view));
    Now, while the focus is still within the tab contents, try to switch to any other tab (e.g. by clicking on the tab headers, or by using the mnemonic keys 'ALT + 1' to 'ALT + 4')...
    ... then you'll notice the following usability issue:
    1) JRE 1.6 causes the focus to transfer to the JButton (which is outside of the tabs entirely) first; then
    2) In response to the JButton gaining focus, the 'auto-scrolling' feature scrolls down to the bottom of the form, to show the JButton. At this point, the tab headers are hidden from view since there are many child components; then
    3) JRE 1.6 transfers the focus to the tab contents; then
    4) The 'auto-scrolling' feature scrolls up to the selected tab's contents, but the tab header itself is still hidden from view (as a side effect of the behavior above); then
    5) Users are forced to manually scroll up to see the tab headers whenever they are just switching between tabs.
    In short, the tab headers will be hidden when users switch tabs, due to the Java 6 behavior posted above.
    That is why it is important for me to prevent the behavior in my first post above (so that it won't cause usability issues when we apply the 'auto-scrolling' feature to our forms).
    Best Regards,
    James

  • Keyboard shortcuts in JTabbedPane don't work in BorderLayout

    I'm mystified by a problem that doesn't seem to make any sense. I have a JTabbedPane with mnemonics, that used to work well before. But since I've shuffled components around a bit and put the JTabbedPane in the BorderLayout.CENTER of a JPanel, the keyboard shortcuts no longer work.
    The appropriate letters are underlined, but the Alt+letter sequence no longer switched tabs. Other components (JButtons) with keyboard shortcuts in the same JPanel, but in the BorderLayout.SOUTH or elsewhere, work as expected.
    It sounds like a bug to me, but is there perhaps a workaround?
    Thanks,
    - Peter

    I keep replying to my own posts...
    I figured out that the tabs start working once a component in them (say, a JTextField) receives keyboard focus. It does sound a bit suspicious to me, but I can live with it.
    Unfortunately, setting the focus programmatically doesn't seem to work: requestFocus() or requestFocusInWindow() on the first JTestBox simply don't work.
    - Peter

  • Add tool tip to left right button in JTabbedPane??

    Hi,
    I am using a tabbed pane with follwong setting.
    tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    So when the no of tab is more a left right button appears.
    I want to add tool tip to these button
    How do i get the instance of these buttons
    thnx
    Neel

    try this for east/west, similar for north/south
    (hopefully there's an easier way)
    import java.awt.*;
    import javax.swing.*;
    class Testing extends JFrame
      public Testing()
        setLocation(300,200);
        setSize(150,100);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JTabbedPane tp = new JTabbedPane();
        tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        tp.setUI(new MyUI());
        for(int x = 0; x < 12; x++)
          JPanel p = new JPanel();
          p.add(new JLabel(""+x));
          tp.addTab(""+(char)(x+65),p);
        getContentPane().add(tp);
      class MyUI extends javax.swing.plaf.metal.MetalTabbedPaneUI
        protected JButton createScrollButton(int direction)
          if (direction != SOUTH && direction != NORTH && direction != EAST && direction != WEST)
              throw new IllegalArgumentException("Direction must be one of: SOUTH, NORTH, EAST or WEST");
          return new ScrollableTabButton(direction);
        private class ScrollableTabButton extends javax.swing.plaf.basic.BasicArrowButton implements javax.swing.plaf.UIResource,SwingConstants
          public ScrollableTabButton(int direction)
            super(direction, UIManager.getColor("TabbedPane.selected"),
                             UIManager.getColor("TabbedPane.shadow"),
                             UIManager.getColor("TabbedPane.darkShadow"),
                             UIManager.getColor("TabbedPane.highlight"));
            if(direction == WEST) setToolTipText("<<<<<");
            else if(direction == EAST) setToolTipText(">>>>>");
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • Bug in BasicTabbedPaneUI Action keys?

    Can someone tell me if the following is a bug or purposeful behavior:
    in jdk1.4.1 I map keystroke F5 to the BasicTabbedPaneUI action "navigateNext". This action eventually gets passed down to the navigateSelectedTab(int direction) method.
    In the first switch statement, it does:
    switch(tabPlacement) {
    case NEXT:
    selectNextTab(current);
    break;
    HOWEVER, tabPlacement is defined to be SwingConstants.TOP, in fact, NEXT isn't EVER even a valid value for the JTabbedPane tabPlace. This action class therefore won't ever do anything.
    Lastly, I'd like to complain that all the action classes in BasicTabbedPaneUI are private. In fact, a lot of UI class methods are private when I'd really prefer to subclass them.
    Thanks.

    Yes, that looks like a bug to me. The NEXT and PREVIOUS values are supposed to indicate the direction of navigation, not the placement of the tabs. They should either check for those values before going into the switch, or add them to the inner switches, after the tab placement has been determined.
    Those two values were added to SwingConstants in jdk1.4, and it looks like someone screwed up retrofitting BasicTabbedPaneUI to use them. (This is exactly the kind of bug that typesafe enums are meant to prevent; too bad we had to wait until jdk1.5 for those.) Do you want to file the bug report, or should I?

  • Problem with scroll tab layout in JtabbedPane

    Pls. if anyone know this, help me
    I have a problem, my scroll tab layout policy does not working when I set it to UI.
    import javax.swing.*;
    import javax.swing.plaf.basic.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.plaf.*;
    public class Components_Area extends JFrame{
         JTabbedPane tab = new JTabbedPane(JTabbedPane.TOP,JTabbedPane.SCROLL_TAB_LAYOUT);
         JLabel l[] = new JLabel[5];
        public Components_Area() {
              tab.setUI(new TestPlaf());
              tab.addTab("Untitled",l[0]);
              tab.addTab("Untitled",l[1]);
              tab.addTab("Untitled",l[2]);
              tab.addTab("Untitled",l[3]);
              tab.addTab("Untitled",l[4]);
              getContentPane().add(tab);
        public static void main(String args []) {
             Components_Area frame = new Components_Area();
             frame.setSize(200,200);
             frame.show();
         static class TestPlaf extends BasicTabbedPaneUI {
              protected LayoutManager createLayoutManager() {
                   return new TestPlafLayout();
              protected Insets getTabInsets(int tabPlacement,int tabIndex) {               
                   Insets defaultInsets = (Insets)super.getTabInsets(tabPlacement,tabIndex).clone();
                   defaultInsets.right += 50;
                   defaultInsets.top += 2;                
                   return defaultInsets;
              class TestPlafLayout extends TabbedPaneLayout {
                   //a list of our close buttons
                   java.util.ArrayList closeButtons = new java.util.ArrayList();
                   public void layoutContainer(Container parent) {
                        super.layoutContainer(parent);
                        //ensure that there are at least as many close buttons as tabs
                        while(tabPane.getTabCount() > closeButtons.size()) {
                             closeButtons.add(new CloseButton(closeButtons.size()));
                        tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
                        Rectangle rect = new Rectangle();
                        int i;
                        for(i = 0; i < tabPane.getTabCount();i++) {
                             rect = getTabBounds(i,rect);
                             JButton closeButton = (JButton)closeButtons.get(i);
                             //shift the close button 3 down from the top of the pane and 20 to the left
                             closeButton.setLocation(rect.x+rect.width-20,rect.y+4);
                             closeButton.setSize(15,15);
                             tabPane.add(closeButton);
                        for(;i < closeButtons.size();i++) {
                             //remove any extra close buttons
                             tabPane.remove((JButton)closeButtons.get(i));
                   // implement UIResource so that when we add this button to the 
                   // tabbedpane, it doesn't try to make a tab for it!
                   class CloseButton extends JButton implements javax.swing.plaf.UIResource {
                        public CloseButton(int index) {
                             super(new CloseButtonAction(index));
                             setBorder( BorderFactory.createEmptyBorder() );
                        setToolTipText("Close this tab");
                             //remove the typical padding for the button
                             setMargin(new Insets(0,0,0,0));
                        addMouseListener(new MouseAdapter() {
                                  public void mouseEntered(MouseEvent e) {                           
                                   setBorder( BorderFactory.createLineBorder(Color.black, 1 ));
                                 public void mouseExited(MouseEvent e) {                                
                                      setBorder( BorderFactory.createEmptyBorder() );
                   class CloseButtonAction extends AbstractAction {
                        int index;
                        public CloseButtonAction(int index)     {
                             super("x");
                             this.index = index;
                        public void actionPerformed(ActionEvent e) {
                             tabPane.remove(index);
    }     Message was edited by:
    henyo

    If someone knows this, help me!

  • Can't drag the border of JTabbedPane

    Hi,
    I met a problem in programming JTabbedPane. I am now fixing some bugs in a existing project, so I am not familar with JTabbedPane.
    In my case, I am not able to adjust the size of JTabbedPane by dragging the border of it. This JTabbedPane is in the right side of a JSplitPane. However, if the right side pane is replaced by a JLabel, then I can drag the border of JLabel.
    I don't why it happens? Does this mean once a JTabbedPane is created (includes it's component inside), I can't change it size anymore? Is there any one who can give me any ideas?
    Thanks
    Feng

    Yes, I also got this conclusion. The problem is caused by the size of inside component.
    There are one JLabel and one JTextField inside my JToolbar. If the string in the JTextField is short, I am able to adjust the width of JToolbar, however, only made it bigger. But if the text inside the JTextField is longer than than the width of screen. the edge of JToolbar is no longer able to be adjusted.
    I know the cause is the size of text in the JTextField. It made the JTextField very long. I know the reason, but I don't know how to solve it. Any one could help me for that?
    Thanks
    Feng

  • BUG REPORT: 2 JTextComponents using the same Document

    When 2 JTextComponents use the same Document they should show the same.
    However when you add them to JTabbedPane to 2 different tabs, one does not show the document correctly, until you resize the window.
    Compile and run the code example to see for yourself.
    If you append "<first message"> and "<second message>" the first tab will show the correct document:
    <first message>
    <second message>
    But if you then switch to the second tab (do not switch to it earlier), you will see:
    <first message><second message>
    <second message>
    Add some more messages to see the effect and then resize the window to see the problem dissappear magically.
    --> Code example <--
    package testproject;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    * @author Geoffrey
    public class TestProject extends JFrame implements ActionListener {
         public static void main(String[] args) {
              TestProject currentFrame = new TestProject();
              currentFrame.pack();
              currentFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Optional
              currentFrame.setVisible(true);
         private JLabel label = new JLabel("Append 2 or more different messages and switch tab. "
         + "Resizing the window will solve the bug.");
         private JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP,
                                                                                         JTabbedPane.WRAP_TAB_LAYOUT);
         private JTextField textField = new JTextField("<first message>");
         private JButton button = new JButton("Append message");
         private StyledDocument document = new DefaultStyledDocument();
         private JTextPane firstTextPane;
         private JTextPane secondTextPane;
         public TestProject() {
              super("TestProject");
              setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              // configure the components
              firstTextPane = new JTextPane(document); // Uses the same document as secondTextPane
              tabbedPane.add("Orginal tab", firstTextPane);
              secondTextPane = new JTextPane(document); // Uses the same document as firstTextPane
              tabbedPane.add("Click here after appending 2 different messages", secondTextPane);
              textField.addActionListener(this);
              button.addActionListener(this);
              // configure the layout and add the components
              Container contentPanel = getContentPane();
              GridBagLayout layout = new GridBagLayout();
              contentPanel.setLayout(layout);
    GridBagConstraints constraints = new GridBagConstraints();
              constraints.fill = GridBagConstraints.BOTH;
              constraints.insets = new Insets (10, 10, 10, 10);
              constraints.weightx = 1.0;
              constraints.weighty = 0.0;
              constraints.gridx = 0;
              constraints.gridy = 0;
              contentPanel.add(label, constraints);
              constraints.weighty = 1.0;
              constraints.gridy = 1;
              contentPanel.add(tabbedPane, constraints);
              constraints.weighty = 0.0;
              constraints.gridy = 2;
              contentPanel.add(textField, constraints);
              constraints.gridy = 3;
              contentPanel.add(button, constraints);
         public void actionPerformed(ActionEvent event) {
              String message = textField.getText();
              SimpleAttributeSet simpleAttributeSet = new SimpleAttributeSet();
              StyleConstants.setFontFamily(simpleAttributeSet, "Monospaced");
              StyleConstants.setForeground(simpleAttributeSet, Color.BLACK);
              try {
                   document.insertString(document.getLength(), message + "\n",
                                                      simpleAttributeSet);
              } catch (BadLocationException exception) {}

    duplicate of:
    Table Location Error Oracle and SqlServer
    closing and locking
    Ludek

  • Strangeness Using HTML with JTabbedPane

    I'm getting some weird behavior when using html format for a JTabbedPane. It seems when I create tabs using HTML, it works fine, but when I subsequently try to change the tab title using JTabbedPane.setTitleAt(), the title doesn't change. The title doesn't change only when I create it with html. If I use "normal" text, the title changes fine.
    I imagine JTabbedPane has a problem with html. I am using version 1.3 and compiling with JBuilder. Below is an example of my program. Uncomment mentioned lines to see it react strangely.
    Any help would be appreciated.
    -joel
    package junk;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BugExample extends JFrame {
    BugExample() {
    super( "Bug Example" );
    JTabbedPane tabs = new JTabbedPane();
    JPanel aPan= new JPanel();
    //html for tab index 0
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 1: " +
    "<font color=#008040>5.6%</b></font></font></center></html>", new JPanel());
    //"Normal" text for tab index 0. If I use this, then the setTitleAt works
    // properly. To try this, make sure the previous addTab() is commented out
    // tabs.addTab("Rate 1:5.7%", new JPanel());
    //html for tab index 1
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 2: " +
    "<font color=#008040>9.2%</b></font></font></center></html>", new JPanel());
    getContentPane().add(tabs);
    //Uncomment next line and run again using the html style addTab() for index 0.
    // I would think the tab at index 0 would show this new text
    // In fact, it will if I do not use html for index 1.
    // tabs.setTitleAt(0, "Rate it again");
    setSize( 400, 220 );
    public static void main(String[] args) {
    BugExample frame = new BugExample();
    frame.addWindowListener( new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
         System.exit(0);
    System.err.println("Starting");
    frame.setVisible(true);

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BugExample extends JFrame {
    BugExample() {
    super( "Bug Example" );
    JTabbedPane tabs = new JTabbedPane();
    JPanel aPan= new JPanel();
    //html for tab index 0
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 1: <font color=#008040>5.6%</b></font></font></center></html>", new JPanel());
    //"Normal" text for tab index 0. If I use this, then the setTitleAt works
    // properly. To try this, make sure the previous addTab() is commented out
    // tabs.addTab("Rate 1:5.7%", new JPanel());
    //html for tab index 1
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 2: <font color=#008040>9.2%</b></font></font></center></html>", new JPanel());
    getContentPane().add(tabs);
    //Uncomment next line and run again using the html style addTab() for index 0.
    // I would think the tab at index 0 would show this new text
    // In fact, it will if I do not use html for index 1.
    tabs.setTitleAt(0, "Rate it again");
    setSize( 400, 220 );
    public static void main(String[] args) {
    BugExample frame = new BugExample();
    frame.addWindowListener( new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
    System.exit(0);
    System.err.println("Starting");
    frame.setVisible(true);

Maybe you are looking for

  • Terminal problems

    Hi everyone, Every time I open terminal I get the message below. This only happens in one account in the computer, it does not happen in other accounts. I will appreciate any help to fix the problem. I have a mac book pro, keyboard in spanish, and I

  • RSS XML Files for a Blog and Podcast on Same Website With iTunes Feed

    Does iWeb support both a separate blog and podcast on the same website feeding the Podcast to iTunes? I got my podcast going on iTunes, then it stopped working after I changed the iTunes podcast name in iWeb and didn't edit the xml file. My podcast i

  • Why is the ios7 update freezing at the "updating iCloud settings" page?

    I have updated to ios7, but when i get to the last few steps, the phone stays on the updating iCloud settings forever till the screen locks and i have to start over. Is this normal? What am i doing wrong or what can i do to fix it?

  • How do I get the absolute best performance out of my MacBook Pro while playing Minecraft/Java Based Games?

    I pretty much want to know how to boost my laptop performance for the lowest price. Is there much to do after upgrading to 8 gigs of RAM and a Samsung SSD? Also is there anyway to upgrade a MacBook Pro early 2011 2.0 GHz i7 Graphics card?

  • Table of contents missbehaving

    Hello, I always seem to encounter the same problem when setting-up the TOC of multi chapter books. When I generate my TOC, the Heading 2 (flow A) title which is at the top of the page, always ends up placed after my Sideheads (flow B) which are lower