1

In my program I have a window to pop up when clicked on a button. It does some complex stuff, so it needs to be in it's own class. So instead of multiple JFrames Could I have something else, like a Layout that supports multiple windows. Remember I already have a solution, I'm just asking if there is a better way to do it, a way in which there won't be 1000 task bar icons for 1000 windows.

Roberto Anić Banić
  • 1,411
  • 10
  • 21

2 Answers2

4

Really, how you configure your GUI will all depend on your needs at the time, and so there really is no one-size-fits-all answer to your question. But having said that, I will recommend that you,

  1. Gear your Swing GUI classes, the "view" classes, towards creating JPanels.
  2. Then you can easily add these views any place you'd like, in a JFrame, a JDialog, a JApplet, another JPanel, a JTabbledPane, a JScrollPane, JInternalFrame, as part of a CardLayout "card",.... This will give your programs tremendous flexibility.
  3. If you need to swap "views" in a single GUI, consider using a CardLayout to do this. The CardLayout-using JPanel would be the displayer, and the "card" JPanels would be viewed in turn under the control of the CardLayout.
  4. If you need to display an independent window, and need to freeze the calling window, then put your view into a modal JDialog or JOptionPane (which is really nothing but a JDialog with some syntactic sugar).
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
2

If you absolutely need to display a new window for every task that is launched, then have a look at JInternalFrame. These can be created inside a parent window, and will not create a new taskbar icon everytime you create one.

Otherwise, if you don't need a new window for every task, you should look into creating different threads for your tasks. There is a lot of documentation available if you google "java concurency".

Laf
  • 7,965
  • 4
  • 37
  • 52