• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing application using netBeans IDE

 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Syam Sathyan George
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried as mentioned by Syam. But still it is not visible.

 
Shashika Thiran
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic