无模式对话框JAVA,Java全屏模式对话框

How does one create a custom modal JDialog that can be used as an internal dialog? For use in FullscreenExclusiveMode.

I have a JScrollPane (with a huge scrollbar) full of huge buttons like so:

+----------------------+------+

| FOO | /\ |

|______________________+------+

| |______|

| BAR | |

|______________________| == |

| |______|

| BIZ | |

+______________________+------+

| | \/ |

|----------------------+------+

I need the user to use the giant scrollbar to scroll through and tap a particular button to select it and close the dialog. The dialog is in fullscreen exclusive mode. The close button needs to be disabled and it needs to not have okay or cancel buttons, whichever button they click needs to update a value and then call frame.dispose() on the dialog.

Right now I'm using an internal frame but the frame isn't popping up in front of everything else because I'm not using a JDesktop. I've also tried JDialog but it minimizes the app.

JOptionPane.showInternalDialog() works but how do I construct my own internal dialogs in the same fashion so that they can be shown? If I make an internal frame and then add it to a component it just sits within that component and not on top of everything.

EDIT: Looked through those classes and tried the popup factory but the popups don't seem to work reliably in fullscreen.

EDIT: Trying JOptionPane.createInternalFrame() here is the demo I'm working with but it doesn't seem to be working yet.

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);

}

}

解决方案

The message argument to the JOptionPane constructor can be a Component as well as a string, e.g. it could be your JScrollPane.

To remove the standard buttons from the option pane, call setOptions(Object[]) with an empty array.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值