Results 1 to 5 of 5
Thread: displaying JSplitPane in JPanel
- 07-23-2010, 01:34 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 4
- Rep Power
- 0
displaying JSplitPane in JPanel
hello everybody,
i wanted Jsplitpane to be added in a Jpanel, which i further added to frame,
when i add jsplitpane directly to frame, it works well.
here is the code,
import javax.swing.*;
class splitpanedemo{
JSplitPane jp;
splitpanedemo(){
JFrame jf=new JFrame("demo");
jp=new JSplitPane();
jf.show();
jf.setVisible(true);
jf.add(jp);
jf.setSize(1500,1500);
}
public static void main(String[] args){
new splitpanedemo();
}
}
but when i want jsplitpane to be added on a panel, which i did through this code
import javax.swing.*;
class splitpanedemo{
JSplitPane jp;
JPanel jpa;
splitpanedemo(){
JFrame jf=new JFrame("demo");
jpa=new JPanel();
jp=new JSplitPane();
jf.show();
jf.setVisible(true);
jpa.add(jp);
jf.add(jpa);
jf.setSize(1500,1500);
}
public static void main(String[] args){
new splitpanedemo();
} }
this won't work well, the output differs,
the divider won't work well,
plz help me out of this.
thank you in advance.
- 07-23-2010, 03:48 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
First of all edit your posting and repost your code using the "Code tags" so the posted code retains its formatting and is readable.
In the first case the split pane is added to the content pane which uses a BorderLayout. The split pane is added to the CENTER which means it gets all the space available to the BorderLayout.
In the second case you add the split pane to the panel which uses a FlowLayout by default. In this case the FlowLayout uses the preferred size of the the split pane. Since you haven't added any components to the split pane or set its preferred size you get the results you see. Try setting the preferred size.
Read Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing) for more information.
- 07-23-2010, 04:43 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 4
- Rep Power
- 0
Hello camickr,
What preferred size should i use, Please reply with a code snippet.
Thank youLast edited by sandysm; 07-24-2010 at 03:54 AM.
-
Please do us all a favor and avoid use of non-standard abbreviations in your posts here. For many here, English is not their primary language, and also since clarity of communication is paramount if you want to make it easy for others to help you, you really don't want to make others struggle to understand you.
- 07-26-2010, 09:13 AM #5
This is what you did.Java Code:JSplitPane jp; JPanel jpa; splitpanedemo(){ JFrame jf=new JFrame("demo"); jpa=new JPanel(); jp=new JSplitPane(); jf.show(); jf.setVisible(true); jpa.add(jp); jf.add(jpa); jf.setSize(1500,1500);
output does differ, you made frame visible first and then added JSplitpane later. Not good idea, add everything first then show frame at the last and yeah use frame.pack().this won't work well, the output differs,
the divider won't work well,
-Regards
Similar Threads
-
Jpanel and displaying graphics
By jdsflash in forum New To JavaReplies: 6Last Post: 11-21-2009, 01:14 AM -
Managing jPanels in jSplitPane
By calexander in forum Advanced JavaReplies: 6Last Post: 11-13-2008, 07:06 PM -
JSplitPane Arranging Components(JTree) Doubt
By hemanthjava in forum AWT / SwingReplies: 0Last Post: 08-03-2008, 08:29 AM -
JSplitPane nightmare
By SwinGirl in forum SWT / JFaceReplies: 1Last Post: 05-01-2008, 08:24 PM -
I need create a JSplitPane
By Daniel in forum AWT / SwingReplies: 1Last Post: 07-05-2007, 06:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks