Forums Register Login

Swing application using netBeans IDE

+Pie Number of slices to send: Send
I have a swing application developed using text editor. As I found it bit difficult to play around with layout manager, I thought of giving it a try using netbeans and slowly converting my original application. I have few buttons and JPanel. I am trying to add dynamically generated components like Jlabel and Jcheck box into my JPanel. Everything works perfectly fine without any error but I am not seeing any dynamically generated components inside my JPanel. What might be the problem? Thanks.
+Pie Number of slices to send: Send
I tried a small example as below. I created JPanel inside the frame using palette. And I added the code below into actionPerformed of a button.


Nothing is visible inside the JPanel (jPanel1). But when I count the number of components inside that JPanel, I am getting the correct number of components generated inside that JPanel. Why the dynamically generated components are invisible? Thanks.
+Pie Number of slices to send: Send
This is a small example. The label is not visible in the JPanel. Since I used netbeans I am posting the entire code generated. Please let me know why the component JLabel is not visible inside the panel. Still I couldn't figure it out.


[ April 08, 2008: Message edited by: Gopu Akraju ]
+Pie Number of slices to send: Send
Hi,

Add the following code to locate your component in case its not drawn in visible are due to size issues. Trust me Netbeans generated Group Layouts can be tricky in space determination of components before laying them out!!

JLabel label =new JLabel("Hi");
label.setBorder(BorderFactory.createLineBorder(Color.Blue));
label.setPrefferedSize(new Dimension(60,30));

panel.add(label);


--Syam.Sathyan
+Pie Number of slices to send: Send
I tried as mentioned by Syam. But still it is not visible.

+Pie Number of slices to send: Send
I,m not expert in java.I have same problem you mention.Accidently i found solution for that question.
Answer:
Create jframe in netbeans.
add panel to frame.
then right click on panel & go set layout.
select Grid layout.
now

Jlabel l=new Jlabel("Hiiii");
jpanel.add(l);
jpanel.revalidate();

It's work for me.
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 9711 times.
Similar Threads
java swings paint
Layouts inside panel
Java bean Persistence not working
How to use java.awt.Image with HTML?
How to use java.awt.Image with HTML?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:32:58.