aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes problem in JSplitPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem in JSplitPane" Watch "problem in JSplitPane" New topic
Author

problem in JSplitPane

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
not able to add into JSplitPane..

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
public class Ctank {
static String sometext = "This is a simple text to test.....";
public static void main(String args[])
{
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setSize(800,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextArea jt1 = new JTextArea(sometext);
Cpoint point = new Cpoint();
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, point, jt1);
frame.getContentPane().add(sp, BorderLayout.CENTER);
}
}

i m not able to add components to JSplitPane, here i m trying to add simple a JTextField and one class CPoint (which exteding JPanel), but on the frame, when i m executing the code nothing is visible to me, what wrong i am doing???
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
run the code again, now drag the frame a little wider.

if the components appear now, read through every line of your code (visualizing what's happening at that line)
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
yes now my components are appearing, but not all (ie. my background is not visible and few more thing are not visible to me).
and why is this happening i mean why it's visible to me when i m dragging it, and why everything is not visible to me??
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
What happens here

JFrame frame = new JFrame(); 
frame.setVisible(true); //<-----------
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
okay now working for me...




but one problem is still here, i m not getting all the fishes (contents of Cpoint class) when i m executing one the code, but when i execute it twice or thrice, suddenly it gives me all the fishes.???
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
i m trying to add one more panel to JSplitPane but i m unable to add, here what i am doing is:

Dynamic.java



Ctank.java



the Cpoint class is visible to me but the Dynamics class is not visible to me....???
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> but the Dynamics class is not visible to me....???

yes it is - you haven't added anything to it.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
but i have added to my panel

panel.add(button);
panel.add(label);


and panel i m adding to JSplitPane..
than??
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> and panel i m adding to JSplitPane..

no, you're not.

read your code.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
but here i m adding.

JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, d, point);


d is object if dynamic class, and that i am adding to JSplitPane..
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> and panel i m adding to JSplitPane..
> d is object if dynamic class, and that i am adding to JSplitPane..

one or the other, which is it?

you can't program using a stick - you need to *read* what you're doing
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
hummm, not getting what mistake i m doing, i was also adding a JTextField in the same way, and that was visible to me but Dynamic class is not....
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
when i m simply running my Dynamic class by creating Main into this, it running, but not when adding to splitpane.....
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> when i m simply running my Dynamic class by creating Main into this, it running, but not when adding to splitpane.....

look very closely at exactly *what* you add to each.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
okay done it..

JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, d.panel, point);

Thank you....
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
well i got the Dynamic class in my Frame no issue, but what is happening here is:

from my Cpoint Class only one object of my Cfish class is visible on frame, i mean i added many objects of of my Cfish class to Cpoint class but only one(last i created) is visible to me, where the rest are gone??

here is my Cpoint class


here only ball6 is visible to me...not the other balls...
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this is now a different topic and should be in its own thread,
plus you'll get more lookers at it because its new, instead of 15+ replies already.

what you've posted, only people can guess because they don't know
what Cfish and Cbubble are.

here's the best thing you can do

1)
in Cpoint just add one Cfish. if it displays/moves fine, move onto (2)

2)
now add just one Cbubble. if it displays/moves fine, move onto (3)

3)
return to (1), repeat until something doesn't work.

when you're at that point, you can post the code with a note
saying it worked fine until I added .....

you would need to post it as an executable program that we can
copy/paste/compile/run/observe, stripping everything unrelated
so the code is as short as possible.

one thing you might also want to try is to slow down the timer
i.e. 26 is about 40 times per second to draw 6 fish and 10 bubbles
so try making it 500 and see if there's any difference
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
okay i will post it in a new thread, and i change the timer to 500 and my all fishes are visible to me but their movement speed gets very much slow..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in JSplitPane