File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Jframe , on resize throws exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jframe , on resize throws exception" Watch "Jframe , on resize throws exception" New topic
Author

Jframe , on resize throws exception

khaja mohideen
Greenhorn

Joined: May 20, 2011
Posts: 12
Hi

On reszie of jframe i.e. my masterframe , throws the following exception and main components ( jtable inside the jframe ) does not resize anymore and
i get the following messages. Please give me clue , to look for a solution

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.DefaultComboBoxModel.getElementAt(Unknown Source)
at javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize(Unknown Source)
at javax.swing.plaf.metal.MetalComboBoxUI.getMinimumSize(Unknown Source)
at javax.swing.JComponent.getMinimumSize(Unknown Source)
at java.awt.FlowLayout.minimumLayoutSize(Unknown Source)
at java.awt.Container.minimumSize(Unknown Source)
at java.awt.Container.getMinimumSize(Unknown Source)
at javax.swing.JComponent.getMinimumSize(Unknown Source)
at javax.swing.BoxLayout.checkRequests(Unknown Source)
at javax.swing.BoxLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at java.awt.BorderLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.BoxLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source)
at java.awt.Container.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at java.awt.BorderLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Regards
kmm
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Please give me clue , to look for a solution

post your code (simplified version producing error)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
I doubt greatly that that Exception has anything to do with resizing.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

The exception is triggered by the resizing (as can be seen by all the layout manager calls in the stack trace), but my guess is that both the NullPointerException and ArrayIndexOutOfBoundsException are caused by updates to the GUI from a thread other than the EDT.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
I acknowledge my mistake, Rob.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

I checked out the code of BoxLayout.preferredLayoutSize which is causing the NullPointerException. There are three candidates there: a field called xTotal is null, a field called yTotal is null, or the component returns null from getInsets(). These two fields are set from private method checkRequests(), so these can't really be the problem. That leaves getInsets() returning null.

I'm 90% sure that the ArrayIndexOutOfBoundsException is caused by a threading issue. BasicComboBoxUI.getDisplaySize() only calls the combo box model's getValueAt method if the model's getSize() method returns a value > 0. DefaultComboBoxModel's getElementAt method is again protected against that:
So the only way that this ArrayIndexOutOfBoundsException could have occurred is if between the checking of the index and the retrieval of the element (between lines 2 and 3 of that code snippet) the model is changed. That can only occur if that's done by another thread, which means updating the model from a thread that isn't the EDT.
khaja mohideen
Greenhorn

Joined: May 20, 2011
Posts: 12
Hi

thank you for the replies , i am now analysing on basis of what you have suggested

just to add , this exception seems to occur only in some cases where i read a text file and update JTable( which is done inside a thread) inside the frame

after which . on resizing the mainframe , the jtable does not resize

regards
khaja mohideen
Greenhorn

Joined: May 20, 2011
Posts: 12
Hi



// this is done in constructor
fsPanel = new JPanel();
//fsPanel.setLayout(new BorderLayout());
fsPanel.setLayout(new BoxLayout(fsPanel, BoxLayout.PAGE_AXIS));
fsPanel.add(filterPanel,"North");
fsPanel.add(timePanel);
fsPanel.add(searchPanel,"South");
---------------------------------------------------------

public void setPanelEnabled(boolean enabled){
for(int i = 0; i < fsPanel.getComponentCount(); i++){
JPanel compPanel = (JPanel) fsPanel.getComponent(i);
for(int j = 0; j < compPanel.getComponentCount(); j++){
compPanel.getComponent(j).setEnabled(enabled);
}
}
}



i write a method setPanelEnabled to enable/disable components of the panel ( which are checkboxes,comboboxes)

this method was causing the problem , i think there is something not clean in this code
as i am new to java , your insight will help me.

but any way thankyou for the replies which helped me to track the problem is short time.

Regards
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4572
    
    5

khaja mohideen wrote:... ( which is done inside a thread) ...

Tutorial: Concurrency in Swing. Also, search the net for "Swing's single threaded rule"


luck, db
There are no new questions, but there may be new answers.
 
GeeCON Prague 2014
 
subject: Jframe , on resize throws exception