aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Best Method for Second Interface Screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Best Method for Second Interface Screen" Watch "Best Method for Second Interface Screen" New topic
Author

Best Method for Second Interface Screen

Ian Taylor
Greenhorn

Joined: Sep 03, 2012
Posts: 21
Hi there

I have only been learning Java for a month or so, so apologies if this question is bit silly or if I get some of my terminology wrong.

I have recently been learning about Swing components. I am building a small program that uses a JFrame as it's main interface (which I built using Netbeans). When a certain button is pressed I want another menu to open, which will allow the user to add/remove items from an array (it will need a JList, a text input field and two buttons).

What is the best way to do this? I have read that it is bad coding practice to open multiple JFrames at once for various reasons. Should I be using JOptionPane or Dialog instead? Every tutorial I can find on using these seems to involve using them to display simple messages or a simple user input (such as Yes/No). I haven't found a tutorial on how to inbed other jComponents inside, or even to what extent it is possible.

Any help appreciated
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1666
    
    7

Hi, and welcome to JavaRanch!

I agree you shouldn't just open new JFrames willy-nilly, because users are bound to get annoyed at such a thing.
The same goes for modal pop-ups within a JFrame, though. Furtunately there are other options. You could use a CardLayout to switch out (a part of) the content of a JFrame. There's also JDesktopPane/JInternalFrame, if a multiple-document interface makes more sense. Or a JTabbedPane if working with tabs would be the most user friendly option.

I've moved your topic to our Swing / AWT / SWT forum by the way


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Ian Taylor wrote:Should I be using JOptionPane or Dialog instead? Every tutorial I can find on using these seems to involve using them to display simple messages or a simple user input (such as Yes/No). I haven't found a tutorial on how to inbed other jComponents inside, or even to what extent it is possible.

Something missed by most beginners, as it's not really clear from any of the popular tutorials, is that the message argument to JOptionPane's show...Dialog(...) methods is declared as Object. JOptionPane is one of the smartest classes in the JDK: it can deal with a Component or an array as a message, not just with simple Strings.

I suggest you write a small class just with a main(...) method that creates a message, and displays it in a JOptionPane's dialog. Its capabilities may impress you. If you're not sufficiently impressed, try an array (Component[] or JComponent[]) filled with different subclasses.


luck, db
There are no new questions, but there may be new answers.
Ian Taylor
Greenhorn

Joined: Sep 03, 2012
Posts: 21
Thanks for the replies and thanks Jelle for moving my post to the correct forum.

I have read all the options that you suggested Jelle, but none of them really seem to suit my needs. I want it so that the new interface pops open in a new window, not a new tab or a new section of the old window or anything like that. It's not like they will be opening willy-nilly, it's just this one screen that will be treated as a separate interface.

Darryl thanks for the reply, but unfortunately I don't understand much of what you said. I am very new to Java and object programming in general (I posted this in the newbie forum, before Jelle moved it). If I understand you right you seem to be suggesting that the 'message' displayed in a JOptionPane can be an object rather than just a string. Can it handle more than one object? As described above, could I make a JOptionPane that could handle a JList, two buttons and a text input? I can't find any tutorial or sample code that shows how to do this.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Ian Taylor wrote:As described above, could I make a JOptionPane that could handle a JList, two buttons and a text input?

You can put those components in a JPanel, using an appropriate layout manager or combination of nested layouts, and pass the panel as the message argument.

You can find the description of how the message and other parameters are interpreted and used in the opening paragraphs of the API for JOptionPane (<- click that if you don't know where to find the API).
Ian Taylor
Greenhorn

Joined: Sep 03, 2012
Posts: 21
Cheers, I'll check out that possibility. I have the second JFrame running okay independently, it's just linking the two together I am having problems with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best Method for Second Interface Screen
 
Similar Threads
displaying data from database
To Hans: When to use JSF?
JOptionPane or JFrame?
GUI Pieces and Parts Not Sticking! Help!
swing using visual editor in eclipse