Skip to main content

How minimize or close subwindows with the mainscreen?

9 replies [Last post]
nerj
Offline
Joined: 2009-01-07

Hi! all,
I develop a simple swing based application. In that, we go through many forms(JFrame) by the mainscreen. When user click minimise button on main screen, only that window be minimised. Is there any way to close or minimize the total applicaiton forms using the mainscreen minimise option? Please suggest me the solution---------

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joshefin
Offline
Joined: 2007-11-25

Your main form could be a JFrame and others JWindow.

nerj
Offline
Joined: 2009-01-07

Hi! Thanks for replying,
I already tried JWindow, but the input fields(JTextField) could not get focus on JWindow.

joshefin
Offline
Joined: 2007-11-25

Use Component.requestFocusInWindow() or Component.requestFocus().

nerj
Offline
Joined: 2009-01-07

Thank u,
ok, But if only one componet is exists, we call requestFocus() method of it. If more than 10 components exists on window, then Shall we call requestFocus() for all components before displaying the window?, or Is there any way to do this?

joshefin
Offline
Joined: 2007-11-25

I think that you don't understand how focusing works. Read [url=http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html]this[/url].
You can not focus more than one component at a time, and there is no need for that. For example, if you have window with few textfields, just request focus for the first ...

nerj
Offline
Joined: 2009-01-07

Hi!
I gone through the doc at the link u specified, I used JWindow for displaying components, and also call the method requestFocusInWindow() of component(TextField) before window has displayed (as specified by doc). But, I can't get focus of the component.
Pls, suggest me the solution -----

walterln
Offline
Joined: 2007-04-17

From [url=http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/FocusSpec.html]AWT Focus Subsystem[/url]:
> Swing allows applications to create JWindows with null owners. Swing constructs all such JWindows so that they are owned by a private, hidden Frame. Because the showing state of this Frame will always be false, a JWindow constructed will a null owner can never be the focused Window, even if it has a Window focusability state of true.

So either set the JWindow parent correctly to a visible JFrame, or use an undecorated JFrame instead.

joshefin
Offline
Joined: 2007-11-25

You can add a WindowListener to your main window, so when it's minimized it'll set the state of other windows/frames (get them with Frame.getFrames()). Look at code below ...

[code]
public class FramesTest {

public FramesTest() {
JFrame frameMain = new JFrame("Main frame");
frameMain.add(new JLabel("This is a main frame, if you minimize it all frames will be minimized too.", JLabel.CENTER));

frameMain.addWindowListener(new WindowAdapter() {
@Override
public void windowIconified(WindowEvent e) {
for (Frame f : JFrame.getFrames())
if (!f.equals(e.getWindow()))
f.setExtendedState(JFrame.ICONIFIED);
}

@Override
public void windowDeiconified(WindowEvent e) {
for (Frame f : JFrame.getFrames())
if (!f.equals(e.getWindow()))
f.setExtendedState(JFrame.NORMAL);
}
});

frameMain.setSize(500, 400);
frameMain.setLocationRelativeTo(null);
frameMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frameMain.setVisible(true);

JFrame frameToolbar = createFrame("Toolbar", new Rectangle(frameMain.getX() + frameMain.getWidth() + 20, frameMain.getY(), 80, 300));
frameToolbar.setVisible(true);

JFrame frameMenu = createFrame("Menu", new Rectangle(frameMain.getX(), frameMain.getY() - 90, 500, 60));
frameMenu.setVisible(true);
}

private JFrame createFrame(String title, Rectangle bounds) {
JFrame frame = new JFrame(title);
frame.setBounds(bounds);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

return frame;
}

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new FramesTest();
}
});
}
}
[/code]

nerj
Offline
Joined: 2009-01-07

Thanks joshefin for ur reply,
It has working.
Can u please, tell me how to manage single form name(Man Application form) on windows task bar. I mean that, if we enter another form through main window, in windows task bar, we see the two name of Main, and subForm. I required to display only main Form name, instead. Is ther any possibility. Please suggest me--------