免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6123 | 回复: 2

Swing如何弹出一个Panel [复制链接]

论坛徽章:
0
发表于 2007-10-03 16:49 |显示全部楼层
setVisible()函数为什么不起作用?



/*
* PlatformJFrame.java
*
* Created on 2007年10月3日, 下午3:25
*/

package testplatform;

/**
*
* @author  xiaodwan
*/
public class PlatformJFrame extends javax.swing.JFrame {
   
    /** Creates new form PlatformJFrame */
    public PlatformJFrame() {
        initComponents();
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">                          
    private void initComponents() {
        helpContentJPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        helpCancelJButton = new javax.swing.JButton();
        platformMenu = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        helpContentMenuItem = new javax.swing.JMenuItem();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setText("hello world!");
        jScrollPane1.setViewportView(jTextArea1);

        helpCancelJButton.setText("Cancel");

        javax.swing.GroupLayout helpContentJPanelLayout = new javax.swing.GroupLayout(helpContentJPanel);
        helpContentJPanel.setLayout(helpContentJPanelLayout);
        helpContentJPanelLayout.setHorizontalGroup(
            helpContentJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, helpContentJPanelLayout.createSequentialGroup()
                .addContainerGap(384, Short.MAX_VALUE)
                .addComponent(helpCancelJButton)
                .addContainerGap())
        );
        helpContentJPanelLayout.setVerticalGroup(
            helpContentJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(helpContentJPanelLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 581, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(helpCancelJButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Test Platform");
        jMenu1.setText("File");
        platformMenu.add(jMenu1);

        jMenu2.setText("Project");
        jMenuItem3.setText("New Project");
        jMenu2.add(jMenuItem3);

        jMenuItem1.setText("Open Project");
        jMenu2.add(jMenuItem1);

        jMenuItem2.setText("Close Project");
        jMenu2.add(jMenuItem2);

        platformMenu.add(jMenu2);

        helpMenu.setText("Help");
        helpContentMenuItem.setText("Content");
        helpContentMenuItem.setActionCommand("PanelUI");
        helpContentMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpContentMenuItemActionPerformed(evt);
            }
        });

        helpMenu.add(helpContentMenuItem);

        platformMenu.add(helpMenu);

        setJMenuBar(platformMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 275, Short.MAX_VALUE)
        );
        pack();
    }// </editor-fold>                        

    private void helpContentMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        helpContentJPanel.setVisible(true);
    }                                                   
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PlatformJFrame().setVisible(true);
            }
        });
    }
   

   
    // 变量声明 - 不进行修改                     
    private javax.swing.JButton helpCancelJButton;
    private javax.swing.JPanel helpContentJPanel;
    private javax.swing.JMenuItem helpContentMenuItem;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JMenuBar platformMenu;
    // 变量声明结束                  
   
}

论坛徽章:
0
发表于 2007-10-03 18:55 |显示全部楼层
看了一天的source不想再看了,为什么不用dialog?

论坛徽章:
0
发表于 2007-10-07 20:50 |显示全部楼层
JPanel和JFrame不一样,不能独立显示,只能依附于某一个JFrame
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP