Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: What's the best way to generate several independent GUIs?
    primarykey
    data
    text
    <p>I need to display multiple images so that users may compare them and I'm not sure what method to use. I have an app that allows the user to choose image files so I have a File Object. I've tried to generate new GUIs with "new" but that doesn't work well.</p> <p>Should I code a standalone app (with a main) and use a system call to start them with a new JVM? I'm new at Java and have just touched the surface of AWT and SWING. </p> <p>The class is called thus where name is an arbitrary unique String:</p> <pre><code>ImageWindowStub iw = new ImageWindowStub(name); </code></pre> <p>Here is simple code that demonstrates the problem if called in succession.</p> <pre><code>package fireScience.airborne.image; import java.awt.Dimension; import javax.swing.BoxLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.border.BevelBorder; public class ImageWindowStub { private static JFrame frame; private static JPanel statusPanel; private static JLabel statPixInfoLbl; private static String theString; public ImageWindowStub(String theString) { this.theString = theString; statusPanel = new JPanel(); createAndShowGui(); } private static void createAndShowGui() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { frame = new JFrame(theString); JFrame.setDefaultLookAndFeelDecorated(true); frame.setResizable(true); frame.setSize(300, 200); frame.setLocation(50, 50); statusPanel = new JPanel(); statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED)); statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 24)); statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); statPixInfoLbl = new JLabel("Status Bar"); statPixInfoLbl.setHorizontalAlignment(SwingConstants.LEFT); statusPanel.add(statPixInfoLbl); frame.add(statusPanel); frame.pack(); frame.setVisible(true); } }); } } </code></pre> <p>My core question is "What is the best way to generate multiple independent instances of a GUI class?"</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload