Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Want to display components on a frame after running programm immediately  RSS feed

 
dhan dd
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have designed one frame which code given below. When i run the program, it does not show label,button immediately.for that i have to maximize the screen or enhance the size of frame(output screen) then it shows labels,buttons.
Can anybody give me solution why this happen and what i have to do?

class loginframe extends JFrame
{
JButton b1;

loginframe(String s)
{
super(s);
setSize(500,500);
setVisible(true);
JPanel p=new JPanel();
p.setLayout(null);

JLabel l1=new JLabel("Welcome in Student Record");
l1.setBounds(150,250,700,50);

l1.setFont (new Font ("ITALIC", Font.BOLD, 30));

b1=new JButton("Login");
b1.setBounds(200,350,70,20);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1.addActionListener(this);


p.add(l1);
p.add(b1);
add(p);
}


public static void main(String[] args)
{
loginframe obj=new loginframe("Student Registry");
}
}
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because you call setVisible(true) before you add any components. Make setVisible(true) your last line in the constructor.
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to set a layout to your panel. But in your code, you have set null
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!