JInternalFrame开场和焦点

问题描述 投票:0回答:1

我在DesktopPane中有一些JInternalFrames,我第一次打开它时就注意到了一些东西。

当我第一次打开一个,然后打开第二个时,第一个JInternalFrame将位于第二个之上。我希望它们在彼此之上打开,但这只是第一次发生。我现在意识到这是因为他们被添加的顺序。但我的程序将在桌面窗口加载时检索信息,所以我需要在实际打开窗口之前添加JIF变量。那么,无论添加顺序如何,我如何确保打开的窗口显示在顶部?

我宁愿不使用对话框。

java swing jinternalframe pane
1个回答
0
投票

试试这个代码......

我已经创建了一个示例应用程序供您理解......

public class NewJFrame extends javax.swing.JFrame {


private javax.swing.JButton jButton1;
private javax.swing.JDesktopPane jDesktopPane1;

//This is a Internal Frame I have created
private PaymentInternalFrame payIF;


public NewJFrame() {
    initComponents();
}


private void initComponents() {

    jButton1 = new javax.swing.JButton();
    jDesktopPane1 = new javax.swing.JDesktopPane();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jButton1.setText("Click");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
    jDesktopPane1.setLayout(jDesktopPane1Layout);
    jDesktopPane1Layout.setHorizontalGroup(
        jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 0, Short.MAX_VALUE)
    );
    jDesktopPane1Layout.setVerticalGroup(
        jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 412, Short.MAX_VALUE)
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE)
        .addComponent(jDesktopPane1)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jDesktopPane1))
    );

    pack();
}// </editor-fold>                        



private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try {
        if(payIF==null||payIF.isClosed()){
            payIF = new PaymentInternalFrame();
            mainDesktop.add(payIF);
            payIF.setVisible(true);
            payIF.setMaximum(true);
            payIF.isSelected();
        }else{
            payIF.setSelected(true);
        }
    } catch (PropertyVetoException e) {
        NotificationMessage.errorMessage(this, e);
    }
}                                        



//Main Method...


public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new NewJFrame().setVisible(true);
        }
    });
}

}

© www.soinside.com 2019 - 2024. All rights reserved.