Reputation: 58
I am trying to create a GUI with a main window for input, and a separate box to show output below the main window. However, the width of the output box will be different from the main window and I don't want the difference in width to be part of the frame (meaning that the difference should be invisible and user can click through the empty space to the back of the application).
But I also want to output box to be shown as 1 window with the main window. I can set the position of the output box with a listener to make it stick to the main window, but I don't want it to be shown as a separate window in the Windows(Microsoft) task bar. I also don't want the output box to be selectable as a result of being a separate window.
Therefore is there any method to create a JPanel outside JFrame, or is there a way I can do this with JFrame and make it work with my constraints? Any other methods?
Upvotes: 1
Views: 1016
Reputation: 1
JDialog
How about to put 2 internal Frames(one is decorated, another one - undecorated und not selectable) or 1 internal Frame and panel in one big translucent undecorated Frame?
At first you will get only one icon in the Windows(Microsoft) task bar. Internal frames wont show up in the task bar.
The main frame should be translucent : how to set JFrame background transparent but JPanel or JLabel Background opaque?
Upvotes: 0
Reputation: 285405
Show the separate JPanel in a window as a non-modal JDialog. You can make it undecorated if you don't want the menu buttons on the top right.
I'm not sure what you mean by:
(meaning that the difference should be invisible and user can click through the empty space to the back of the application).
Regarding
I also don't want the output box to be selectable as a result of being a separate window.
Make sure that you have no focusable components in the dialog, or if focusable, have the focusable property set to false.
Edit
To prevent the dialog window from being focused, add a line:
dialog.setFocusableWindowState(false);
For example:
import java.awt.Dimension;
import javax.swing.*;
public class DialogNoFocus {
public DialogNoFocus() {
// TODO Auto-generated constructor stub
}
private static void createAndShowGui() {
DialogNoFocus mainPanel = new DialogNoFocus();
JFrame frame = new JFrame("JFrame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(Box.createRigidArea(new Dimension(400, 300)));
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
JDialog dialog = new JDialog(frame, "JDialog", false);
dialog.getContentPane().add(Box.createRigidArea(new Dimension(500, 100)));
int x = frame.getLocation().x;
int y = frame.getLocation().y + frame.getHeight();
dialog.setLocation(x, y);
dialog.pack();
dialog.setFocusableWindowState(false);
dialog.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}
Upvotes: 3