1

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);
}
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Wesos de Queso
  • 1,526
  • 1
  • 21
  • 23
  • `setLayout(null);` Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Apr 28 '16 at 07:14
  • envase.getWidth() envase.getHeight() print the above two return values, you will come to know. – shimbu shambu Apr 28 '16 at 09:39
  • @shimbushambu tried it, no idea why is it reducing the bounds. Solved it setting size after creating a new instance of the JPanel, now works fine. – Wesos de Queso Apr 29 '16 at 05:48
  • please vote for comment so that any one can easily find answer. – shimbu shambu Apr 29 '16 at 08:41

1 Answers1

5
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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433