![](/img/trans.png)
[英]Is there a definite Selenium solution to modal pop up dialogs in Internet Explorer with Java?
[英]Java Fullscreen Modal Dialogs
如何創建可用作內部對話框的自定義模態 JDialog? 用於 FullscreenExclusiveMode。
我有一個 JScrollPane(帶有一個巨大的滾動條),里面裝滿了像這樣的巨大按鈕:
+----------------------+------+
| FOO | /\ |
|______________________+------+
| |______|
| BAR | |
|______________________| == |
| |______|
| BIZ | |
+______________________+------+
| | \/ |
|----------------------+------+
我需要用戶使用巨大的滾動條滾動並點擊一個特定的按鈕到 select 它並關閉對話框。 該對話框處於全屏獨占模式。 關閉按鈕需要被禁用,並且它不需要有確定或取消按鈕,無論他們單擊哪個按鈕都需要更新一個值,然后在對話框上調用 frame.dispose()。
現在我正在使用一個內部框架,但由於我沒有使用 JDesktop,所以該框架並沒有出現在其他所有東西的前面。 我也嘗試過 JDialog 但它最小化了應用程序。
JOptionPane.showInternalDialog() 有效,但我如何以相同的方式構建自己的內部對話框以便顯示它們? 如果我制作一個內部框架,然后將其添加到一個組件中,它只是位於該組件內,而不是位於所有內容之上。
編輯:瀏覽了這些類並嘗試了彈出工廠,但彈出窗口似乎不能在全屏模式下可靠地工作。
編輯:在這里嘗試 JOptionPane.createInternalFrame() 是我正在使用的演示,但它似乎還沒有工作。
public class FullscreenDialog {
public static final void main(final String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());//uses os window manager
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(800,600));
final JLabel label = new JLabel("Something to say.");
panel.add(label);
final JFrame fullscreenFrame = new JFrame();
fullscreenFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
fullscreenFrame.setUndecorated(true);//To remove the bars around the frame.
fullscreenFrame.setResizable(false);//resizability causes unsafe operations.
fullscreenFrame.setContentPane(panel);
fullscreenFrame.validate();
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(fullscreenFrame);//actually applies the fullscreen.
final JOptionPane optionPane = new JOptionPane();
optionPane.add(new JLabel("Some alert"));
final JButton button = new JButton();
button.setText("Press me.");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
label.setText("worked");
optionPane.setValue(button);
}
});
JInternalFrame frame = optionPane.createInternalFrame(panel, "Internal Dialog");
frame.setVisible(true);
}
}
JOptionPane
構造函數的message
參數可以是Component
也可以是字符串,例如它可以是您的JScrollPane
。
要從選項窗格中刪除標准按鈕,請使用空數組調用setOptions(Object[])
。
JOptionPane.showXXXDialog(...) 允許在創建自定義內部對話框時進行大量自定義。
嘗試這個..
.
.
.
final JOptionPane optionPane = new JOptionPane();
optionPane.add(new JLabel("Some alert"));
final JButton button = new JButton();
button.setText("Press me.");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
label.setText("worked");
fullscreenFrame.invalidate();
fullscreenFrame.repaint();
optionPane.setValue(button);
}
});
JInternalFrame frame = optionPane.createInternalFrame(panel, "Internal Dialog");
frame.getContentPane().removeAll();
JPanel pnl = new JPanel(new BorderLayout());
pnl.add( button, BorderLayout.SOUTH );
pnl.add( new JScrollBar(), BorderLayout.CENTER );
frame.getContentPane().add( pnl );
frame.setVisible(true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.