Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding Components in JSplitPane  RSS feed

 
Rani Vish
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I have a doubt ,Whenever i add in JSplitPane with Component like JPanel or JDesktopPane it won't complain ,but when i add Frame or JFrame it throw exception ,why it happen ,As we know JSplitPAne add Component as its letf or right components,and Component is the super class of All Components and Containers,Why it is not adding Frame as its component

Thanks
 
Campbell Ritchie
Sheriff
Posts: 55280
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, a JFrame is a Component, but you are supposed to use it as a Container, which it also is. You aren't supposed to to put a Frame inside anything else (except a JInternalFrame).
The add methods are in the Container class, the only add method in Component being add(PopupMenu).
What sort of Exception are you getting?
 
Rani Vish
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply
but still not clear about ,why it is adding JDesktopPane and not JFrame ,as both are used as Container

After giving this statement

Component comp1 = new JDesktopPane();
Component comp2 = new JFrame(" Adding Frame in Split pane");
JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,comp1,comp2);


it throws

java.lang.IllegalArgumentException: adding a window to a container

at java.awt.Container.addImpl(Container.java:616)

at javax.swing.JSplitPane.addImpl(JSplitPane.java:1006)

at java.awt.Container.add(Container.java:518)

at javax.swing.JSplitPane.setRightComponent(JSplitPane.java:495)

at javax.swing.JSplitPane.<init>(JSplitPane.java:333)

at com.test.TabbedPaneEx1.jbInit(TabbedPaneEx1.java:36)

at com.test.TabbedPaneEx1.<init>(TabbedPaneEx1.java:27)

at com.test.TabbedPaneEx1.main(TabbedPaneEx1.java:60)
 
Rani Vish
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply
but still not clear about ,why it is adding JDesktopPane and not JFrame ,as both are used as Container

After giving this statement

Component comp1 = new JDesktopPane();
Component comp2 = new JFrame(" Adding Frame in Split pane");
JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,comp1,comp2);


it throws

java.lang.IllegalArgumentException: adding a window to a container

at java.awt.Container.addImpl(Container.java:616)

at javax.swing.JSplitPane.addImpl(JSplitPane.java:1006)

at java.awt.Container.add(Container.java:518)

at javax.swing.JSplitPane.setRightComponent(JSplitPane.java:495)

at javax.swing.JSplitPane.<init>(JSplitPane.java:333)

at com.test.TabbedPaneEx1.jbInit(TabbedPaneEx1.java:36)

at com.test.TabbedPaneEx1.<init>(TabbedPaneEx1.java:27)

at com.test.TabbedPaneEx1.main(TabbedPaneEx1.java:60)
 
Rani Vish
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply
but still not clear about ,why it is adding JDesktopPane and not JFrame ,as both are used as Container

After giving this statement

Component comp1 = new JDesktopPane();
Component comp2 = new JFrame(" Adding Frame in Split pane");
JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,comp1,comp2);


it throws

java.lang.IllegalArgumentException: adding a window to a container

at java.awt.Container.addImpl(Container.java:616)

at javax.swing.JSplitPane.addImpl(JSplitPane.java:1006)

at java.awt.Container.add(Container.java:518)

at javax.swing.JSplitPane.setRightComponent(JSplitPane.java:495)

at javax.swing.JSplitPane.<init>(JSplitPane.java:333)

at com.test.TabbedPaneEx1.jbInit(TabbedPaneEx1.java:36)

at com.test.TabbedPaneEx1.<init>(TabbedPaneEx1.java:27)

at com.test.TabbedPaneEx1.main(TabbedPaneEx1.java:60)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!