我在 netbeans 中创建了一个项目.我有一个内部框架,我想将其显示为对话框.请帮我.注意:我使用的是 windows 外观.
I have created one project in netbeans. I have one internal frame, which I want to be displayed as dialog. Please help me. Note:I have used windows look and feel.
不要使用 java.awt.Dialog 或 javax.swing.JDialog.而是查看 JOptionPane以 'showInternal..' 开头的 code> 方法.例如
Don't use a java.awt.Dialog or javax.swing.JDialog. Instead look to the JOptionPane methods that start with 'showInternal..'. E.G.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
public class InternalDialog {
public static void main(String[] args) throws Exception {
Runnable r = new Runnable() {
@Override
public void run() {
// the GUI as seen by the user (without frame)
JPanel gui = new JPanel(new BorderLayout());
gui.setBorder(new EmptyBorder(2, 3, 2, 3));
JDesktopPane dtp = new JDesktopPane();
gui.add(dtp);
ActionListener listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Component c= (Component)e.getSource();
JOptionPane.showInternalMessageDialog(c, "Message");
}
};
for (int ii=0; ii<3; ii++) {
JInternalFrame jif = new JInternalFrame();
dtp.add(jif);
jif.setLocation(new Point(ii*30, ii*20));
jif.setSize(200,50);
jif.setVisible(true);
JButton b = new JButton("Click me!");
b.addActionListener(listener);
jif.add(b);
}
// TODO!
gui.setPreferredSize(new Dimension(280, 150));
gui.setBackground(Color.WHITE);
JFrame f = new JFrame("Demo");
f.add(gui);
// Ensures JVM closes after frame(s) closed and
// all non-daemon threads are finished
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// See http://stackoverflow.com/a/7143398/418556 for demo.
f.setLocationByPlatform(true);
// ensures the frame is the minimum size it needs to be
// in order display the components within it
f.pack();
// should be done last, to avoid flickering, moving,
// resizing artifacts.
f.setVisible(true);
}
};
// Swing GUIs should be created and updated on the EDT
// http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
SwingUtilities.invokeLater(r);
}
}
这篇关于Java Swing 内部框架作为对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)