Neo87
Neo87

Reputation: 73

Java popup windows freeze during execute kettle on

i have a strange problem, i made a little software on java that execute some jobs i made in kettle. Now, the transformation is going good, everything work, but when i execute transformation i would like to show a message during it

public Wait(){
    setTitle("Aggiungi nuovo autore");
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screen = toolkit.getScreenSize();
    setBounds((screen.width/2)-150, (screen.height/2)-90, 300, 180);
    setResizable(false);
    setDefaultLookAndFeelDecorated(false);
    setContentPane(new Inner());
    setResizable(false);
    setUndecorated(true);
    setVisible(true);
}

public class Inner extends JPanel{
    BufferedImage image;
    public Inner(){
        BoxLayout box = new BoxLayout(this,BoxLayout.PAGE_AXIS);
        setLayout(box);
        JTextPane text = new JTextPane();
        text.setText("Attendere il completamento delle operazioni, potrebbe richiedere tempo");
        text.setOpaque(false);
        StyledDocument doc = text.getStyledDocument();
        SimpleAttributeSet center = new SimpleAttributeSet();
        StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
        doc.setParagraphAttributes(0, doc.getLength(), center, false);
        ImageIcon icon = new ImageIcon("extra/loading.gif");
        JLabel label = new JLabel (icon);
        add(Box.createRigidArea(new Dimension(0,20)));
        add(label);
        add(Box.createRigidArea(new Dimension(0,20)));
        add(text);
        Border border = BorderFactory.createLineBorder(java.awt.Color.DARK_GRAY, 3);
        setBorder(border);
    }
}
}

and i run it in this part of controller

public void actionPerformed(ActionEvent e){
            aggiungi.setEnabled(false);
            Wait wait = new Wait();
            wait.toFront();
            for (int i=0; i<model.effectivilyCount();i++){
                int removed = 0;
                int c = executeCommand(model.getValueAt(i, 0),model.getValueAt(i,1));
                if (c==0) {
                    model.removeRow(removed);
                    model.fireTableDataChanged();
                }
                else if (c==1) ;//errore fatale da implementare
                else if (c==2) ; //segna di rosso e lascia stare nella tabella
            }
            wait.dispose();
            aggiungi.setEnabled(true);
        }

Now, java open the new window (wait) and disable the main window (aggiungi), but it doesn't show what wait contain :(. What i can do about?

PS executeCommand(String,String) run the kettle transformation

Upvotes: 1

Views: 475

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

You've got a threading issue, likely caused by the executeCommand method. You're calling this on the Swing event thread and it's tying up the thread, making your GUI unresponsive. Better to put it in a background thread such as that supplied by a SwingWorker.

In addition, it looks like you're showing a 2nd window that's possibly a JFrame. If so, you're probably better off showing a modal dialog, as the modal part will make your main window inactivated until the dialog is no longer visible.

Upvotes: 2

Related Questions