【发布时间】:2011-04-16 21:34:08
【问题描述】:
是的,我认为通过在组件上使用.getComponents() 会相对简单,这将返回JOptionPane 的JPanel,然后他们通过再次使用该方法和JPanel 检索JButtons但是我面临困难。
我想在JOptionPane 按钮上使用鼠标侦听器,以便在鼠标悬停时更改按钮的颜色。有没有更简单的方法来实现这一点?
到目前为止,这是我的课..
package rsapp.gui;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
public class RSJPaneComponent extends JOptionPane {
/**
*
*/
private static final long serialVersionUID = 13453253L;
private JOptionPane j=this;
final Color WHITE = Color.WHITE;
public RSJPaneComponent(){
UIManager.put("OptionPane.background",WHITE);
UIManager.put("Panel.background",WHITE);
UIManager.put("Button.background",WHITE);
UIManager.put("Button.foreground",new Color(85,153,187));
UIManager.put("activeCaption", WHITE);
}
protected String initJPaneInput(final JFrame f, final String message){
return j.showInputDialog(f,message);
}
public int generateDialog(int error_code, String title_message, String message, final JFrame f){
return JOptionPane.showConfirmDialog(
f,
message,
"Error "+error_code+": "+title_message,
JOptionPane.YES_NO_OPTION);
}
}
【问题讨论】:
-
@Andrew:您应该将此作为答案发布,而不是评论。
-
我将如何使用 JDialog 执行此操作?我不是要代码,只是一些有用的使用方法或如何做的概念。
-
@HFOE 完成。 @unleashed 请确保在以后的帖子中使用代码格式。要使用它,请选择代码示例并单击
{}按钮。检查代码是否按预期显示在消息发布表单下方的预览区域中。 -
虽然你不是要代码,但我加了一些。有时我发现编写示例代码比描述过程更容易和更快。 ;)
标签: java swing joptionpane