How do you make a JPanel a child Widget?

I've made a RisingPanel which is a subclass of JPanel.
I added RisingPanel to the ChatClient's GUI, where I wanted it to appear.

The problem is that the RisingPanel is not visible on the main JFrame. If you look at the RisingPanel code below, you'll see i've added log output on each line so I know the rising panel's instruction set is executed - but I just can't see it.

I'd like to know how to make it visible. I'm pretty sure it has something to do with somehow communicating that RisingPanel is a child widget of ChatClient GUI.

Secondly, how could I find out the parent widget's height and weight. (I think the answer is pretty obvious after the answer to the latter question).

I've made a RisingPanel which is a subclass of JPanel.
I added RisingPanel to the ChatClient's GUI, where I wanted it to appear.

The problem is that the RisingPanel is not visible on the main JFrame. If you look at the RisingPanel code below, you'll see i've added log output on each line so I know the rising panel's instruction set is executed - but I just can't see it.

I'd like to know how to make it visible. I'm pretty sure it has something to do with somehow communicating that RisingPanel is a child widget of ChatClient GUI.

Secondly, how could I find out the parent widget's height and weight. (I think the answer is pretty obvious after the answer to the latter question).

In Swing every JComponent is a Container so that it can contain other JComponents; there are a few 'top level' components: Windows and Dialogs; a Frame (or JFrame) is an extension of a Window; in order for a JComponent to be visible it has to be part of a tree of Components ending at a top level component at the top or root, say a JFrame. If it isn't, it won't be visible. You have to stick your extension of the JPanel somewhere in a tree of Containers ending at a top level component, I don't see that happening in your code.

More important than the code you've shown us is the code for the component that holds and displays the RisingPanel. What layout managers are you using for this container? Are you revalidating and repainting it whenever you add, remove or change the size of a component? Are you using println debug statements to show the size of the RisingPanel instance during the program run? I see you using a background thread to try to change its size -- would you be better off using a Swing Timer to be sure that Swing code (such as your setSize method call) are called on the EDT? Do you need to call setPreferredSize instead of setSize?

More important than the code you've shown us is the code for the component that holds and displays the RisingPanel. What layout managers are you using for this container?

Although Layout Managers are useful, I find them particularly annoying and prefer to use the setBounds() method instead.

Originally Posted by Fubarable

Are you revalidating and repainting it whenever you add, remove or change the size of a component?

The contents of the Rising Panel never get changed. It only exists for a few minutes to get one piece of information - then i dispose it. I could have used JOptionPane but I was going for style and something i'd never tried before.

Originally Posted by Fubarable

Are you using println debug statements to show the size of the RisingPanel instance during the program run?

Yup

Originally Posted by Fubarable

I see you using a background thread to try to change its size -- would you be better off using a Swing Timer to be sure that Swing code (such as your setSize method call) are called on the EDT?

I haven't learnt Swing Timers yet - which is why i haven't used them but I have heard about them and do plan to implement them into the code once I understand how they work.

Originally Posted by Fubarable

Do you need to call setPreferredSize instead of setSize?

I believe setPreferredSize is something that LayoutManagers use. Since I'm not using a Layout manager - i didn't use setPreferred Size.

Although Layout Managers are useful, I find them particularly annoying and prefer to use the setBounds() method instead.

And this is why you're running into this problem. They are only annoying until you learn and understand them, but once you do understand them and use them properly, solving your current problem will be trivial (and in fact this is where they shine). Until you do, solving your problem will be very difficult.

The ActionListener code is counter to the concepts of event-driven programming since you have a while (true) loop present, and this will freeze Swing's main thread, the event dispatch thread, or EDT. Better to simply return from the method if the input field is empty: