首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JOptionPane游标

JOptionPane游标
EN

Stack Overflow用户
提问于 2012-06-20 07:07:49
回答 1查看 839关注 0票数 2

在使用JOprionPane时,我遇到了一些光标问题。我将光标设置为pharent框架,然后使用以下命令显示一个对话框:

代码语言:javascript
复制
Object[] possibilities = {"ham", "spam", "yam"};
String s = (String) JOptionPane.showInputDialog(MagicCollectorClient.getMainFrame(),"Complete the sentence:\n\"Green eggs and...\"",
            "Customized Dialog",JOptionPane.PLAIN_MESSAGE,null,possibilities,"ham");

它会显示对话框,但会将光标更改为默认系统光标,直到我关闭该对话框。有没有办法解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-20 07:36:55

SSCCE呢?是的,这是可能的,你必须从静态方法帮助器中“解绑”JOptionPane,因为你想用它做一些特殊的事情。不幸的是,这意味着你有更多的工作要做,但不会太可怕。

代码语言:javascript
复制
public static void main(String[] args) {
    JFrame parent = new JFrame();
    parent.setSize(400, 400);
    parent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    parent.setVisible(true);

    Object[] possibilities = { "ham", "spam", "yam" };

    // raw pane
    JOptionPane optionPane = new JOptionPane(
            "Complete the sentence:\n\"Green eggs and...\"",
            JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
            possibilities, possibilities[0]);

    // create a dialog for it with the title
    JDialog dialog = optionPane.createDialog("Customized Dialog");

    // special code - in this case make the cursors match
    dialog.setCursor(parent.getCursor());

    // show it
    dialog.setVisible(true);

    // blocking call, gets the selection
    String s = (String) optionPane.getValue();

    System.out.println("Selected " + s);
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11110734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档