• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in JSplitPane

 
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens here

JFrame frame = new JFrame(); 
frame.setVisible(true); //<-----------
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> but the Dynamics class is not visible to me....???

yes it is - you haven't added anything to it.
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> and panel i m adding to JSplitPane..

no, you're not.

read your code.
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay done it..

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

Thank you....
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
reply
    Bookmark Topic Watch Topic
  • New Topic