我使用Popup来显示更新进度。我在主窗口上方放置了一个半透明面板以实现效果。在大多数情况下,Popup是可见的,但在某些计算机上则不然。它似乎与特定的计算机有关。有没有人知道解决方案或有更好的方法来实现它?
//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_progress_TA.requestFocusInWindow();
答案 0 :(得分:3)
确保:
答案 1 :(得分:2)
考虑更好地寻找/使用未装饰的模型JDialog or JWindow(默认未修饰)而不是JPopup