My swing application in java 5 which had a display like
After migrating to java 8, zoomed up and displays only a part of it like
I saw this and tried setting J2D_D3D as environment variable and also tried passing it as a vm parameter. But didn't solved the issue. Any idea what this could be?
For reference, here's an example the doesn't have the problem. It uses a GridLayout(0, 1)
with congruent gaps and border. Resize the enclosing frame to see the effect. Experiment with Box(BoxLayout.Y_AXIS)
as an alternative.
I suspect the original code (mis-)uses some combination of setXxxSize()
or setBounds()
, which will display the effect shown if the chosen Look & Feel has different geometry specified by the buttons' UI delegate.
import java.awt.EventQueue;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/** @see https://stackoverflow.com/a/31078625/230513 */
public class Buttons {
private void display() {
JFrame f = new JFrame("Buttons");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel(new GridLayout(0, 1, 10, 10));
p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
for (int i = 0; i < 3; i++) {
p.add(new JButton("Button " + (i + 1)));
}
f.add(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Buttons()::display);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With