C
chris.allport
Greetings, All-
I am having difficulty getting my application configured the way I
would like. This is a really standard thing, so I must be missing
something simple. I am hoping some of you might have a better idea
than I do about this.
The main application should appear in the main frame. I can make this
happen.
The problem is when I popup other windows. They either don't show up,
or they are behind the main window. I have read about mixing AWT and
Swing, but I thought I was using all Swing.
Also, I could not find any guidelines explaining when I should use
JInternalFrames versus JDialog, so I am just using internal frames.
Currently, I am attempting something similar to the following:
class MyApp extends JFrame {
MyApp() {
super("MyApp");
desktopPane = new JDesktopPane();
getContentPane().add(...);
}
...
}
To add a popup:
public class MyPopup extends JPanel
implements InternalFrameListener {
private JInternalFrame frame;
private JDesktopPane desktopPane;
public MyPopup(JDesktopPane dtPane) {
desktopPane = dtPane;
initComponents();
}
public void run(int width, int height) {
createAndShowGUI(width, height);
}
private void initComponents() {
// Add components to GUI
...
}
private void createAndShowGUI(int width,
int height) {
frame = new JInternalFrame("MyPopUp",
false,
false,
false,
false);
frame.setBackground(Color.gray);
this.setBackground(Color.gray);
frame.setSize(width, height);
//Create and set up the content pane.
this.setOpaque(true);
frame.setContentPane(this);
//frame.getContentPane().add(this); // didn't work either
//Display the window.
frame.setVisible(true);
desktopPane.add(frame);
frame.moveToFront();
}
}
The code instantiates this panel from a menu action listener as
follows:
private class MyPopupListener implements ActionListener {
public MyPopupListener() {
}
public void actionPerformed(ActionEvent e) {
MyPopup gui = new MyPopup(desktopPane);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
gui.run(150, 220);
}
});
}
}
This never shows up. Any ideas?
Thanks in advance-
Chris
I am having difficulty getting my application configured the way I
would like. This is a really standard thing, so I must be missing
something simple. I am hoping some of you might have a better idea
than I do about this.
The main application should appear in the main frame. I can make this
happen.
The problem is when I popup other windows. They either don't show up,
or they are behind the main window. I have read about mixing AWT and
Swing, but I thought I was using all Swing.
Also, I could not find any guidelines explaining when I should use
JInternalFrames versus JDialog, so I am just using internal frames.
Currently, I am attempting something similar to the following:
class MyApp extends JFrame {
MyApp() {
super("MyApp");
desktopPane = new JDesktopPane();
getContentPane().add(...);
}
...
}
To add a popup:
public class MyPopup extends JPanel
implements InternalFrameListener {
private JInternalFrame frame;
private JDesktopPane desktopPane;
public MyPopup(JDesktopPane dtPane) {
desktopPane = dtPane;
initComponents();
}
public void run(int width, int height) {
createAndShowGUI(width, height);
}
private void initComponents() {
// Add components to GUI
...
}
private void createAndShowGUI(int width,
int height) {
frame = new JInternalFrame("MyPopUp",
false,
false,
false,
false);
frame.setBackground(Color.gray);
this.setBackground(Color.gray);
frame.setSize(width, height);
//Create and set up the content pane.
this.setOpaque(true);
frame.setContentPane(this);
//frame.getContentPane().add(this); // didn't work either
//Display the window.
frame.setVisible(true);
desktopPane.add(frame);
frame.moveToFront();
}
}
The code instantiates this panel from a menu action listener as
follows:
private class MyPopupListener implements ActionListener {
public MyPopupListener() {
}
public void actionPerformed(ActionEvent e) {
MyPopup gui = new MyPopup(desktopPane);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
gui.run(150, 220);
}
});
}
}
This never shows up. Any ideas?
Thanks in advance-
Chris