Java Swing内部框架作为对话框
我在netbeans中创建了一个项目。我有一个内部框架,我想显示为对话框。请帮帮我。Java Swing内部框架作为对话框,java,swing,dialog,jinternalframe,Java,Swing,Dialog,Jinternalframe,我在netbeans中创建了一个项目。我有一个内部框架,我想显示为对话框。请帮帮我。 注意:我使用了windows的外观。Swing有自己的本机外观。您可以在JDialog上记录自己。对于平台外观,请尝试使用SWT。下次请更具体地回答你的问题。祝你好运。不要使用java.awt.Dialog或javax.swing.JDialog。相反,请查看以“showInternal..”开头的。例如 import java.awt.*; import java.awt.event.*; import ja
注意:我使用了windows的外观。Swing有自己的本机外观。您可以在
JDialog
上记录自己。对于平台外观,请尝试使用SWT。下次请更具体地回答你的问题。祝你好运。不要使用java.awt.Dialog
或javax.swing.JDialog
。相反,请查看以“showInternal..
”开头的。例如
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);
}
}
import java.awt.*;
导入java.awt.event.*;
导入javax.swing.*;
导入javax.swing.border.EmptyBorder;
公共类内部对话框{
公共静态void main(字符串[]args)引发异常{
Runnable r=新的Runnable(){
@凌驾
公开募捐{
//用户看到的GUI(无框架)
jpanelgui=newjpanel(newborderlayout());
setboorder(新的EmptyBorder(2,3,2,3));
JDesktopPane dtp=新JDesktopPane();
添加(dtp);
ActionListener=新建ActionListener(){
@凌驾
已执行的公共无效操作(操作事件e){
组件c=(组件)e.getSource();
showInternalMessageDialog(c,“消息”);
}
};
对于(int ii=0;ii)注意:我使用了windows的外观。不要这样做,将其设置为。您的Linux&OS X用户会感谢您的。@AndrewThompson,这是唯一的方法吗?方法showInputDialog(组件父组件、对象消息、对象初始选择值)
没有内部对应项。@ryvantage(耸耸肩)我不太使用内部框架。你可以改为使用。。