Wesos de Queso
Wesos de Queso

Reputation: 1572

JDialog gets smaller everytime gets dispose/setVisible(true)

First time called

enter image description here

[10 time called][3]

enter image description here

After more interactions the JDialog ends into a floating title bar. Resizing it "resets" the cicle. Heres the code from the JPanel that calls this JDialog. Don´t know what makes it smaller, just noticed it after spamming this button.

public class Mant_presentacion extends JPanel implements ActionListener{

Boton buscar_envase = new Boton(this, new ImageIcon("lupa.png"));   
Mant_env envase = new Mant_env();   
public final JFrame OWNER;

public Mant_presentacion(JFrame OWNER){
    this.OWNER = OWNER;
    setLayout(null);
    setBackground(Color.WHITE);
    d = new JDialog(OWNER, "Seleccionar envase", true);
    buscar_envase.setBounds(500, 50, 180, 30);
    buscar_envase.setText(" Examinar envases");
    buscar_envase.addActionListener(this);
}

JDialog d;

@Override
public void actionPerformed(ActionEvent e) {
    d.setSize(envase.getWidth(), envase.getHeight());
    d.add(envase);
    d.setLocationRelativeTo(null);
    d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    d.setVisible(true);
}
}

Upvotes: 1

Views: 56

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168825

d.setSize(envase.getWidth(), envase.getHeight());

A dialog has decorations around the boundary. If code sets the dialog (d) size to that of the content (envase) it will shrink a little each time.

Upvotes: 5

Related Questions