开发者

Java: Popup not always visible

I use a Popup to display an update progress. I put a semi-transparent panel above the main window for effect. In far the most cases the Popup is visible but on some computers it's not. It seems to be related to specific computers. Does anyone know a solution or have a better way to implement this?

//Disable main components
tabs.setEnabledAt(0, false);
tabs.setEnabledAt(1, false);
comPorts_CB.setEnabled(false);
getinfo_B.setEnabled(false);
//Add effect panel
pop_effect_panel = new JPanel();
pop_effect_panel.setBackground(new Color(255, 255, 255, 192));
pop_effect_panel.setBounds(0, 0, 1000, 1000);
pop_effect_panel.setLayout(null);
pop_effect_panel.setOpaque(true);
getContentPane().add(pop_effect_panel);
getContentPane().setComponentZOrder(pop_effect_panel, 0);
getContentPane().setEnabled(false);
pop_effect_panel.invalidate();
//Create pop-up panel
pop_panel = new JPanel();
pop_panel.setBackground(BACKGROUND_COLOR);
pop_panel.setSize(300, 300);
pop_panel.setLayout(null);
pop_panel.setOpaque(true);
pop_panel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
pop_progress_TA = new NonSelectableTextArea();
pop_progress_TA.setBounds(2, 2, 296, 268);
pop_progress_TA.setBackground(BACKGROUND_COLOR);
pop_panel.add(pop_progress_TA);
pop_progress_bar = new JProgressBar();
pop_progress_bar.setBounds(1, 270, 240, 28);
pop_progress_bar.setValue(0);
pop_progress_bar.setStringPainted(true);
pop_progress_bar.setString("");
pop_panel.add(pop_progress_bar);
pop_ok_B = new JButton("OK");
pop_ok_B.setBounds(241, 270, 57, 28);
pop_ok_B.setEnabled(false);
pop_panel.add(pop_ok_B);
final Popup popup = PopupFactory.getSharedInstance().getPopup(getContentPane(), pop_panel, 100, 250);
popup.show();
pop_ok_B.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        popup.hide();
        //Remove effect panel
        getContentPane().remove(pop_effect_panel);
        getContentPane().validate();
        //Enable main components
        tabs.setEnabledAt(0, true);
        tabs.setEnabledAt(1, true);
        comPorts_CB.setEnabled(true);
        getinfo_B.setEnabled(true);
    }
});
pop_pr开发者_JS百科ogress_TA.requestFocusInWindow();


Ensure that:

  • The progress dialog is created and updated on the EDT.
  • The long running task is completed off the EDT.


consider that would be better look for/using un-decorated Modal JDialog or JWindow (by defalut un-decorated) instead of JPopup

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜