Java Utililty Methods JComponent Size

List of utility methods to do JComponent Size

Description

The list of methods to do JComponent Size are organized into topic(s).

Method

voidsetSizeBasedOnResolution(final JComponent component)
Set the size of the JComponent based on the resolution of the screen
Dimension dimension = getDimensionBasedOnResolution();
component.setSize(dimension.width, dimension.height);
voidsetSizes(JComponent[] components, final Dimension dimension)
set Sizes
for (int i = 0; i < components.length; i++) {
    JComponent comp = components[i];
    comp.setPreferredSize(dimension);
    comp.setMaximumSize(dimension);
voidsetSMPSizes(JComponent comp, Dimension d)
set SMP Sizes
comp.setSize(d);
comp.setMinimumSize(d);
comp.setPreferredSize(d);
voidsetUnlimitedSize(JComponent component)
set Unlimited Size
Dimension size = new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
component.setMaximumSize(size);
voidsetZeroMinimumSize(Component component)
Sets the component to a minimum size of zero to allow split panes and layout managers from shrinking the components
if (component instanceof JComponent) {
    ((JComponent) component).setMinimumSize(ZERO_DIMENSION);
voidshow(final JComponent component, final String windowTitle, final Dimension size)
Show the given component in it's own window.
SwingUtilities.invokeLater(() -> showGUI(component, windowTitle, size));
voidshowComponent(JComponent component, Dimension size)
Shows a JFrame containing the specified component.
fixJMenuBug();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(component);
frame.pack();
frame.setVisible(true);
frame.setMinimumSize(size);
JFrameshowGUI(final JComponent newContentPane, final String windowTitle, final Dimension size)
show GUI
final JFrame frame = new JFrame(windowTitle);
newContentPane.setOpaque(true); 
frame.setContentPane(newContentPane);
if (size == null) {
    frame.pack();
} else {
    frame.setSize(size);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
return frame;
voidshowStaticPage(final URI uri, final Dimension size, final Point location)
Creates a frame with a JEditorPane with given URI.
final JFrame frame = new JFrame();
frame.getRootPane().setLayout(new BorderLayout());
JEditorPane editor = new JEditorPane(uri.toString());
editor.setEditable(false);
JScrollPane scrollPane = new JScrollPane(editor);
frame.getRootPane().add(scrollPane);
frame.setAlwaysOnTop(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
...
voidsizeUniformly(JComponent... components)
size Uniformly
for (JComponent c : components) {
    c.setPreferredSize(null);
    c.setMinimumSize(null);
    c.setMaximumSize(null);
int width = 0;
int height = 0;
for (JComponent c : components) {
...