【问题标题】:Java Swing Internal Frame As Dialog [closed]Java Swing内部框架作为对话框[关闭]
【发布时间】:2012-12-13 11:52:26
【问题描述】:

我在 netbeans 中创建了一个项目。我有一个内部框架,我想将其显示为对话框。请帮我。 注意:我使用的是 windows 外观。

【问题讨论】:

标签: java swing dialog jinternalframe


【解决方案1】:

不要使用java.awt.Dialogjavax.swing.JDialog。而是查看以“showInternal..”开头的JOptionPane methods。例如

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);
    }
}

【讨论】:

【解决方案2】:

Swing 有自己的原生外观和感觉。您可以在 JDialog right here 上记录自己。对于平台外观,请尝试使用 SWT。下次请更具体地回答您的问题。祝你好运。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 2013-08-11
    • 2011-12-06
    • 2010-09-23
    • 1970-01-01
    • 2012-06-07
    • 1970-01-01
    相关资源
    最近更新 更多