I'm having endless problems when I need to show the user some very complex interface with save or cancel buttons and need this interface to correctly deal with different monitor resolutions. Suppose for instance this interface needs to fit 17 JTextFields and a resizable JTextArea in a 1280 x 768 monitor (my 13'' laptop has vertical size of 760 pixel).
here is an SSCCE:
import java.awt.*;
import javax.swing.*;
public class OptionPanePanel extends JFrame
{
private static Container layoutComponents(String title, float alignment)
{
JPanel container = new JPanel();
BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
container.setLayout(layout);
for (int i = 0, n = 7; i < n; i++)
{
JTextField jtextField= new JTextField("jtextfield "+i, n);
jtextField.setAlignmentX(alignment);
container.add(jtextField);
container.add( new javax.swing.Box.Filler(new java.awt.Dimension(0, 20), new java.awt.Dimension(0, 20),
new java.awt.Dimension(32767, 20)));
}
JTextArea jTextArea = new JTextArea(15, 30);
container.add(jTextArea);
for (int i = 6, n = 13; i < n; i++)
{
JTextField jtextField= new JTextField("jtextfield "+i, n);
jtextField.setAlignmentX(alignment);
container.add(jtextField);
container.add( new javax.swing.Box.Filler(new java.awt.Dimension(0, 20), new java.awt.Dimension(0, 20),
new java.awt.Dimension(32767, 20)));
}
return container;
}
public static void main(String args[])
{
Container panel1 = layoutComponents("Left", Component.LEFT_ALIGNMENT);
JOptionPane.showConfirmDialog(
null, panel1, "addRecord", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
}
}
Now I would like the above example to behave so that:
- The size of the window resizes not cropping any of the content
- The size of the window somehow deals differently based on the resolution of the monitor.
- I dont' have to statically specify maximumSize, MinimumSize and preferredSize (with the NetBeans GUI editor for instance) so that each time I have to make numerous tests just to find out the correct size
- the JtextArea resizes itself vertically depending on the vertical resolution up to a maximum.