Results 1 to 8 of 8
  1. #1
    geforce2000 is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Default Inconsistent out-of-bounds error

    I’m trying to create and delete tabs dynamically. I’m using a custom library called SytheticaAddons from javasoft.de that’s based off the JTabbedPane component. What I have works, but does so inconsistently. Sometimes it generates an out-of-bounds error. I’ve looked at the code over and over again but can’t spot the problem, so I need another pair of eyes to perhaps see what I can not find.

    Here is the error:
    Java Code:
    run:
    Tab Count: 3
    Tab Count: 4
    Tab Count: 5
    Tab Count: 4
    Tab Count: 5
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 5
    Tab Count: 6
            at javax.swing.plaf.basic.BasicTabbedPaneUI.tabForCoordinate(BasicTabbedPaneUI.java:1488)
            at javax.swing.plaf.basic.BasicTabbedPaneUI.setRolloverTab(BasicTabbedPaneUI.java:558)
            at javax.swing.plaf.basic.BasicTabbedPaneUI.access$2000(BasicTabbedPaneUI.java:37)
            at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mouseEntered(BasicTabbedPaneUI.java:3596)
            at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
            at java.awt.Component.processMouseEvent(Component.java:6225)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
            at java.awt.Component.processEvent(Component.java:5981)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4583)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4413)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
            at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:4345)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4202)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2475)
            at java.awt.Component.dispatchEvent(Component.java:4413)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            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)
    BUILD SUCCESSFUL (total time: 37 seconds)

    And here is the complete code:
    Java Code:
    // TabbedPaneExample.java
    // Libraries needed:
    // Synthetica, SyntheticaAddon and SyntheticaBlackEye
    // located at javasoft.de
    
    import de.javasoft.plaf.synthetica.SyntheticaBlackEyeLookAndFeel;
    import de.javasoft.swing.JYTabbedPane;
    import de.javasoft.swing.JYTabbedPane.CloseButtonStrategy;
    import de.javasoft.swing.SimpleDropDownButton;
    import de.javasoft.swing.ToolBar;
    import de.javasoft.swing.plaf.jytabbedpane.Tab;
    import java.awt.Component;
    import java.awt.Frame;
    import javax.swing.AbstractAction;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    import javax.swing.border.EmptyBorder;
    import java.awt.BorderLayout;
    
    public class TabbedPaneExample extends javax.swing.JFrame {
    
        private JYTabbedPane tabbedPane;
    
        public TabbedPaneExample() {
    
            // frame
            createComponents();
            this.setTitle("Tabbed Pane Demo");
            this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            this.setSize(480, 350);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
    
            // create tabbed pane
            this.tabbedPane = new JYTabbedPane();
            this.tabbedPane.setBorder(new EmptyBorder(5, 5, 5, 5));
            this.tabbedPane.setCloseButtonStrategy(CloseButtonStrategy.SELECTED_TAB);
            this.tabbedPane.getActionMap().put("closeTab", new AbstractAction() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeTabbedPaneActionPerformed(evt); }});
            this.tabbedPane.setFocusable(false);
            this.add(this.tabbedPane);
    
            // create default tabs
            this.tabbedPane.addTab("Tab1", new JPanel());
            this.tabbedPane.addTab("Tab2", new JPanel());
            this.tabbedPane.addTab("Tab3", new JPanel());
            System.out.println("Tab Count: " + tabbedPane.getTabCount());
    
            createToolbar();
    
        }
    
        private void createComponents()
        {
            this.setLayout(new BorderLayout());
        }
    
        private void createToolbar() {
            ToolBar toolBar = new ToolBar();
    
            // drop down button
            SimpleDropDownButton settingsButton = new SimpleDropDownButton("Settings");
            JMenuItem tabbedPaneItem = new JMenuItem("New Tabbed Pane");
            tabbedPaneItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newTabbedPaneItemActionPerformed(evt); }});
            settingsButton.getPopupMenu().add(tabbedPaneItem);
            toolBar.add(settingsButton);
    
            this.add(toolBar, BorderLayout.NORTH);
        }
    
        private void newTabbedPaneItemActionPerformed(java.awt.event.ActionEvent evt) {
    
            // create tabbed pane dialog
            TabbedDialog tabbedPaneDialog = new TabbedDialog((Frame) SwingUtilities.getWindowAncestor(this), true);
    
            // if user did not cancel dialog
            String stringValue = tabbedPaneDialog.getTabTitle();
            if (stringValue!=null) {
                // check that input has some text
                if (stringValue.compareTo("")>0) {
                    this.tabbedPane.addTab(tabbedPaneDialog.getTabTitle(), new JPanel());
                    System.out.println("Tab Count: " + tabbedPane.getTabCount());
                }
            }
        }
    
        private void closeTabbedPaneActionPerformed(java.awt.event.ActionEvent evt) {
    
            // get tab and title
            Tab tab = (Tab)SwingUtilities.getAncestorOfClass(Tab.class, (Component) evt.getSource());
            JLabel label = tabbedPane.getTabLabelAt(tab.getTabIndex());
            String tabTitle = label.getText();
    
            // Create confirmation dialog
            int result = JOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(tab), "Really close tab '" + tabTitle + "'", "Confirmation", JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.YES_OPTION) { tabbedPane.removeTabAt(tab.getTabIndex()); System.out.println("Tab Count: " + tabbedPane.getTabCount()); }
        }
    
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run()
                {
                   try
                    {
                        UIManager.setLookAndFeel(new SyntheticaBlackEyeLookAndFeel());
                        new TabbedPaneExample().setVisible(true);
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            });
        }
    }

    Java Code:
    // TabbedDialog.java
    
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    
    public class TabbedDialog extends javax.swing.JDialog {
    
        private javax.swing.JLabel titleLabel;
        private javax.swing.JTextField titleTextField;
        private javax.swing.JButton okButton;
        private String title = null;
    
        public TabbedDialog(java.awt.Frame parent, boolean modal) {
    
            // frame
            super(parent, modal);
            createComponents();
    
            this.setSize(220, 80);
            this.setTitle("Dialog");
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        }
    
        public void createComponents() {
    
            this.setLayout(new FlowLayout(FlowLayout.LEFT));
    
            this.titleLabel = new JLabel("Title: ");
            this.add(titleLabel);
            
            this.titleTextField = new JTextField("");
            Dimension textFieldSize = this.titleTextField.getPreferredSize();
            this.titleTextField.setPreferredSize(new Dimension(100, textFieldSize.height));
            this.titleTextField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { titleTextFieldActionPerformed(evt); }});
            this.add(titleTextField);
    
            okButton = new JButton("Ok");
            okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); }});
            this.add(okButton);
        }
    
        private void titleTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
    
            this.title = titleTextField.getText();
            this.dispose();
        }
    
        private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
    
            this.title = titleTextField.getText();
            this.dispose();
        }
    
        public String getTabTitle() { return this.title; }
    
        public static void main(String args[]) {
            
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    TabbedDialog dialog = new TabbedDialog(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                        @Override
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                }
            });
        }
    }
    Last edited by geforce2000; 12-23-2009 at 01:29 AM. Reason: I removed all NetBean generated code

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,313
    Blog Entries
    1
    Rep Power
    31

    Default

    Hopefully someone here will be able to help you, but if not, then you may wish to create a small program that doesn't use the proprietary tabbed pane library that you now use, that preferably doesn't use NetBeans-generated code, that we can compile and test ourselves.

    Much luck!

  3. #3
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    285
    Rep Power
    11

    Default

    Note that the intermitency may be related to moving the mouse.

    Maybe this old post can help.
    Last edited by zweibieren; 12-23-2009 at 01:25 AM.

  4. #4
    geforce2000 is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Default

    Hopefully someone here will be able to help you, but if not, then you may wish to create a small program that doesn't use the proprietary tabbed pane library that you now use, that preferably doesn't use NetBeans-generated code, that we can compile and test ourselves.
    I edited and removed all the Netbean generated code in my first post. Hopefully that will help. I'm wondering if there is a bug in the library code I'm using?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,313
    Blog Entries
    1
    Rep Power
    31

    Default

    Quote Originally Posted by geforce2000 View Post
    I edited and removed all the Netbean generated code in my first post. Hopefully that will help. I'm wondering if there is a bug in the library code I'm using?
    I can't say much since I can't compile your code as it depends on the outside library.
    Last edited by Fubarable; 12-23-2009 at 03:24 AM.

  6. #6
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    11

    Default

    fubarable means you import de.javasoft.xxx, which other may not have

  7. #7
    geforce2000 is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Default

    Unfortunately, the problem essentially deals with code from that library, so I can’t really remove it without altering the outcome. And I know most people probably won’t download the evaluation version just to test this code and I don’t blame them. I just thought maybe someone could spot the problem without having to run the code.

    I was able to try a different library called JIDE that was very similar. Unfortunately it doesn’t have the look and feel support that I need. But when I ran that code that was slightly different, it ran fine without any out-of-bounds errors.

    I did manage to condense my original code way down, so maybe this will help:

    Java Code:
    // TabbedPaneExample.java
    
    import de.javasoft.plaf.synthetica.SyntheticaBlackEyeLookAndFeel;
    import de.javasoft.swing.JYTabbedPane;
    import de.javasoft.swing.JYTabbedPane.CloseButtonStrategy;
    import de.javasoft.swing.SimpleDropDownButton;
    import de.javasoft.swing.ToolBar;
    import javax.swing.JFrame;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    import javax.swing.border.EmptyBorder;
    import java.awt.BorderLayout;
    
    public class TabbedPaneExample extends javax.swing.JFrame {
    
        private JYTabbedPane tabbedPane;
    
        public TabbedPaneExample() {
    
            // frame
            this.setLayout(new BorderLayout());
            this.setTitle("Tabbed Pane Demo");
            this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            this.setSize(480, 350);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
    
            // tabbed pane
            this.tabbedPane = new JYTabbedPane();
            this.tabbedPane.setBorder(new EmptyBorder(5, 5, 5, 5));
            this.tabbedPane.setCloseButtonStrategy(CloseButtonStrategy.SELECTED_TAB);
            this.tabbedPane.setFocusable(false);
            this.add(this.tabbedPane);
    
            createToolbar();
    
            // create default tabs
            this.tabbedPane.addTab("Tab1", new JPanel());
            this.tabbedPane.addTab("Tab2", new JPanel());
            this.tabbedPane.addTab("Tab3", new JPanel());
        }
    
        private void createToolbar() {
    
            // toolbar
            ToolBar toolBar = new ToolBar();
    
            // drop down button
            SimpleDropDownButton settingsButton = new SimpleDropDownButton("Settings");
            JMenuItem tabbedPaneItem = new JMenuItem("New Tabbed Pane");
            tabbedPaneItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newTabbedPaneItemActionPerformed(evt); }});
            settingsButton.getPopupMenu().add(tabbedPaneItem);
            toolBar.add(settingsButton);
    
            this.add(toolBar, BorderLayout.NORTH);
        }
    
        private void newTabbedPaneItemActionPerformed(java.awt.event.ActionEvent evt) {
    
            this.tabbedPane.addTab("New", new JPanel());
        }
    
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run()
                {
                   try
                    {
                        UIManager.setLookAndFeel(new SyntheticaBlackEyeLookAndFeel());
                        new TabbedPaneExample().setVisible(true);
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            });
        }
    }
    Last edited by geforce2000; 12-23-2009 at 07:07 AM.

  8. #8
    geforce2000 is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Default

    I contacted the author with the code above. Apparently it is a bug that heíll fix in the upcoming release. He gave me a workaround until then that Iíll try tomorrow.

    Java Code:
    // A workaround is to delay the call of #addTab
        EventQueue.invokeLater(new Runnable()
        {
          public void run()
          {
            tabPane.addTab("New", new JPanel());
          }
        });

Similar Threads

  1. htmlparser inconsistent behavior
    By sjchase in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2009, 11:07 PM
  2. Inconsistent ObjectInput/OutputStreams through Sockets
    By Singing Boyo in forum Advanced Java
    Replies: 1
    Last Post: 06-22-2009, 12:43 AM
  3. Inconsistent layout w/dynamic resize of components
    By donb2000 in forum AWT / Swing
    Replies: 3
    Last Post: 07-26-2008, 02:40 PM
  4. why is my array out of bounds?
    By Phobos0001 in forum New To Java
    Replies: 3
    Last Post: 03-24-2008, 01:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •