gpt4 book ai didi

java - JOptionPane 游标

转载 作者:行者123 更新时间:2023-12-04 05:42:31 29 4
gpt4 key购买 nike

使用 JOprionPane 时,光标出现了一些问题。我将光标设置到 pharent 框架,然后使用这个显示一个对话框:

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

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

最佳答案

怎么样SSCCE ?是的,这是可能的,您必须从静态方法助手中“解绑” JOptionPane,因为您希望对它做一些特别的事情。不幸的是,这意味着您还有更多的工作要做,但没什么可怕的。

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

关于java - JOptionPane 游标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11110734/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com