0

ユーザーが編集ボタンをクリックすると、新しいフレームが表示され、新しいフレームを閉じると、リフレッシュラインを実行したいのですが、問題は、新しいフレームを閉じる前にリフレッシュラインが実行されることです...私は使用していますUIを作成するためのNetBeans。

//If user clicks on edit button new frame will be shown to him 
EditUserFrame editUserFrame = new EditUserFrame();
Iterator itr = userList.iterator();
while(itr.hasNext()){
    user = (Users)itr.next();
    if((user.getF_name().equals(f_name) && user.getL_name().equals(l_name))){
        break;
    }
}//End of While Loop
editUserFrame.setUserObj(user);
editUserFrame.getExistingValues();
editUserFrame.setVisible(true);
//I want this line to be executed when the editUserFrame is closed..
RefreshUserTable();

このような新しいフレームが欲しいのですが、皆さんが提案したように、JOPtionPaneの画像で与えられたフォームを作成することが可能です。

ここに画像の説明を入力してください

4

2 に答える 2

3

ある種のモーダルダイアログを使用したい。ダイアログは、表示された時点でプログラムの実行を「停止」するように設計されています。

ダイアログの作成方法を確認してください。

JOptionPaneさまざまなボタン/オプションを比較的簡単に構成できるため、を使用して好きなものを簡単にすることもできます。概要については、JOptionPaneの機能を確認してください

例で更新

ここに画像の説明を入力してください

public class TestOptionPane01 {

    public static void main(String[] args) {
        new TestOptionPane01();
    }

    public TestOptionPane01() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                }

                FormPane formPane = new FormPane();
                int result = JOptionPane.showConfirmDialog(
                                null, 
                                formPane, 
                                "Edit User", 
                                JOptionPane.OK_CANCEL_OPTION, 
                                -1);

                switch (result) {

                    case JOptionPane.OK_OPTION:
                        System.out.println("You selected okay");
                        break;
                    case JOptionPane.OK_CANCEL_OPTION:
                        System.out.println("You selected cancel");
                        break;

                }

            }
        });
    }

    public class FormPane extends JPanel {

        public FormPane() {

            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.insets = new Insets(2, 2, 2, 2);
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.weightx = 1;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.anchor = GridBagConstraints.WEST;
            add(new JLabel("Edit User"), gbc);
            gbc.gridy++;
            add(new JSeparator(), gbc);

            gbc.gridwidth = 1;
            gbc.weightx = 0;
            gbc.fill = GridBagConstraints.NONE;
            gbc.gridy++;
            add(new JLabel("Fill all fields to edit user tecord"), gbc);

            gbc.gridy++;
            gbc.gridheight = 2;
            add(new JLabel("Select Image Icon"), gbc);
            gbc.gridheight = 1;
            gbc.gridy += 2;
            add(new JLabel("First Name"), gbc);
            gbc.gridy++;
            add(new JLabel("Last Name"), gbc);
            gbc.gridy++;
            add(new JLabel("Password"), gbc);
            gbc.gridy++;
            add(new JLabel("Confirm Password"), gbc);
            gbc.gridy++;
            add(new JLabel("Email Address"), gbc);

            gbc.gridx++;
            gbc.gridy = 3;
            gbc.anchor = GridBagConstraints.EAST;
            add(new JLabel("Maximum Image Size 32x32"), gbc);
            gbc.gridy++;
            add(new JButton("Select"), gbc);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridy++;
            add(new JTextField(10), gbc);
            gbc.gridy++;
            add(new JTextField(10), gbc);
            gbc.gridy++;
            add(new JTextField(10), gbc);
            gbc.gridy++;
            add(new JTextField(10), gbc);

            gbc.gridx++;
            gbc.gridy = 3;
            gbc.anchor = GridBagConstraints.CENTER;
            gbc.gridheight = 3;
            gbc.fill = GridBagConstraints.BOTH;
            JPanel panel = new JPanel();
            panel.setBorder(new BevelBorder(BevelBorder.RAISED));
            add(panel, gbc);
            gbc.gridy += 3;
            gbc.gridheight = 1;
            gbc.fill = GridBagConstraints.NONE;
            add(new JButton("Clear Image"), gbc);

        }

    }


}
于 2012-12-13T08:25:08.333 に答える
1

あなたは使用することができます

'editUserFrame.addWindowListener(new WindowAdapter()
{
    public void windowClosed(WindowEvent e){
    //call your method from here
        RefreshUserTable();
    }
};'

お役に立てれば

于 2012-12-13T09:59:23.710 に答える