noidea
noidea

Reputation: 184

Open second JFrame and components don't show

Before you say something, i know the implications of having more than one JFrame. I'm kinda delayed and i need to add the components manually.

So, i open a JFrame that i have designed with a button click:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

   JFrame DataCalc = new JFrame();
   DataCalc.setVisible(true); 
   DataCalc.setSize(500, 500);
   DataCalc.setLocationRelativeTo(null);   
}      

Then the JFrame shows up but doesn't show my components. I read that if i setVisible before adding components they won't show, but they're already there cause i designed them.

If i change my code and add the setSize and setLocation like the following code, nothing happens besides the JFrame opening.

public DataCalc() {
    this.setSize(500, 500);
    this.setLocationRelativeTo(null);
    initComponents();
}

Sry for the post, i'll edit my post if you need more info.

Upvotes: 1

Views: 117

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168825

JFrame DataCalc = new JFrame();

Should be:

JFrame dataCalc = new DataCalc(); // use the CUSTOM frame!

Upvotes: 3

Related Questions