sách gpt4 ai đã đi

java - 内部 JFrame

In lại 作者:行者123 更新时间:2023-11-29 08:12:34 30 4
mua khóa gpt4 Nike

我想知道如何在 swing 中显示内部框架。这意味着,当需要 JFrame 时,通常我所做的是,

new MyJFrame().setVisible(true);

假设之前的表单也应该显示。当显示这个新框架时,任务栏上会显示另一个新图标。(这听起来像是两个单独的应用程序在一个应用程序中运行)我想避免显示该图标并显示两个框架,因为它们在一个应用程序中。谢谢

1 Câu trả lời

..want to avoid showing that icon and display both frames as they are in one application.

另一个解决方案是将第二个和后续的自由 float 元素放在 JDialog ở giữa.

例如使用框架和对话框来保存额外内容。

nhập java.awt.*;
nhập java.awt.event.*;
nhập javax.swing.*;

class FrameTest {

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
công khai 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;
}
}

关于java - 内部 JFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7262226/

30 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com