我想知道如何在秋千中显示内部框架。这意味着,当需要JFrame时,通常我所做的就是
new MyJFrame().setVisible(true);
假设还应显示上一个表单。当显示这个新帧时,任务栏上会显示另一个新图标(听起来像是在一个应用程序中运行的两个单独的应用程序)我想避免显示该图标并在一个应用程序中显示两个帧。谢谢
答案 0 :(得分:3)
..想要避免显示该图标并在一个应用程序中显示两个帧。
另一个解决方案是将第二个和后续的自由浮动元素放在JDialog
。
E.G。使用框架和对话框来保存额外的内容。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class FrameTest {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
initGui();
}
});
}
public static void initGui() {
final JFrame f = new JFrame("Frame Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel gui = new JPanel(new GridLayout(0,1,5,5));
final Content c = new Content();
JButton frame = new JButton("Frame");
frame.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JFrame f2 = new JFrame("Content");
f2.add(c.getContent());
f2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f2.pack();
f2.setLocationByPlatform(true);
f2.setVisible(true);
}
});
gui.add(frame);
JButton dialog = new JButton("Dialog");
dialog.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JDialog d = new JDialog(f);
d.add(new Content().getContent());
d.pack();
d.setLocationByPlatform(true);
d.setVisible(true);
}
});
gui.add(dialog);
f.add(gui);
f.pack();
f.setVisible(true);
}
}
class Content {
public Component getContent() {
JPanel p = new JPanel();
p.add(new JLabel("Hello World!"));
return p;
}
}
答案 1 :(得分:2)
您有一个JFrame
申请。
您可以在JPanels
中显示多个JFrame
。
或者,正如垃圾邮件指出的那样,JInternalFrames
内可以有多个JDesktopFrame
。