- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想在我的非 RCP SWT 应用程序中添加自定义按钮标题。
MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
messageBox.setText("Warning");
messageBox.setMessage("Save the changes before exiting?");
int buttonID = messageBox.open();
switch(buttonID) {
case SWT.YES:
// saves changes ...
case SWT.NO:
// exits here ...
break;
case SWT.CANCEL:
// does nothing ...
}
System.out.println(buttonID);
}
它工作正常,但我的按钮标题是“中止”、“重试”、“忽略”我想要自定义按钮标题,例如“覆盖”、“重命名”、“取消”。怎么做到的?
请帮忙。
*** 编辑 ********
我也试过
MessageDialog dialog = new MessageDialog(null, "Dangerous Activity", null,
"Are you sure you want to delete?", MessageDialog.CONFIRM,
new String[]{"Preview>", "Delete", "Cancel"}, 0)
{
protected void buttonPressed(int buttonId) {
setReturnCode(buttonId);
// close(); Call close for Delete or Cancel?
}};
但是 MessageDialog 要求应用程序是 RCP,因此没有导入所需的包。帮助。
最佳答案
这是一个非常简单的示例,说明如何在 SWT 中创建您自己的 Dialog
(尽管使用 JFace 可以使用更舒适的方法来执行此操作):
public class CustomDialog extends Dialog
{
private String message = "";
private Shell shell;
public CustomDialog(Shell parent)
{
// Pass the default styles here
this(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell = parent;
}
public CustomDialog(Shell parent, int style)
{
// Let users override the default styles
super(parent, style);
shell = parent;
}
public String getMessage()
{
return message;
}
public void setMessage(String message)
{
this.message = message;
}
public void open()
{
shell.setText(getText());
createContents(shell);
shell.pack();
shell.open();
Display display = getParent().getDisplay();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
}
/**
* Creates the dialog's contents
*
* @param shell
* the dialog window
*/
private void createContents(final Shell shell)
{
shell.setLayout(new GridLayout(3, true));
// Show the message
Label label = new Label(shell, SWT.NONE);
label.setText(message);
GridData data = new GridData();
data.horizontalSpan = 3;
label.setLayoutData(data);
// Display the input box
Label image = new Label(shell, SWT.NONE);
image.setImage(shell.getDisplay().getSystemImage(SWT.ICON_ERROR));
data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
data.horizontalSpan = 3;
image.setLayoutData(data);
Button preview = new Button(shell, SWT.PUSH);
preview.setText("Preview");
data = new GridData(SWT.FILL, SWT.END, true, true);
preview.setLayoutData(data);
preview.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent event)
{
System.out.println("Preview");
}
});
Button delete = new Button(shell, SWT.PUSH);
delete.setText("Delete");
data = new GridData(SWT.FILL, SWT.END, true, true);
delete.setLayoutData(data);
delete.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent event)
{
System.out.println("Delete");
}
});
Button cancel = new Button(shell, SWT.PUSH);
cancel.setText("Cancel");
data = new GridData(SWT.FILL, SWT.END, true, true);
cancel.setLayoutData(data);
cancel.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent event)
{
shell.close();
}
});
shell.setDefaultButton(preview);
}
public static void main(String[] args)
{
CustomDialog dialog = new CustomDialog(new Shell());
dialog.setText("Title");
dialog.setMessage("Message");
dialog.open();
}
}
看起来像这样:
关于java - 带有自定义按钮标题的 SWT MessageBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14832378/
我遇到了一个奇怪的问题。我正在 VC++ 2008 中制作 Win32 应用程序,制作一个类来封装大部分工作,以便在调用 MessageBox 时轻松重复。 .消息框已创建(我认为),但除非我按下 A
如果我的应用程序崩溃,我会使用 ExceptionFilter 来捕获崩溃,执行一些最终操作,然后向用户显示应用程序已崩溃的消息框。 因为应用程序已经崩溃,我能(或不敢)做的事情不多,因为如果我做的太
既然“messagebox”是“tkinter”包中的一个模块,为什么我必须使用 from tkinter import messagebox 代替 import tkinter.messagebox
出于某种原因,WPF MessageBox 看起来比 WindowsForms 中的更糟糕。 WPF 没有视觉样式。 如何将 Windows 样式应用于 WPF MessageBox? Windows
我无法找出两个消息框之间的主要区别。 System.Windows.MessageBox 和 System.Windows.Forms.MessageBox 有什么区别? 最佳答案 System.Wi
我通过将位图的构建操作设置为Splashscreen来使用WPF中的SplashScreen功能。在启动屏幕后面,正在检查许可信息,如果失败,我会显示一个 MessageBox。 根据这个Feedba
我正在使用http://dev.sencha.com/playpen/docs/output/Ext.MessageBox.html#prompt显示 extjs 提示,用户可以在其中输入一些文本,然
有了这个,默认就可以了。我可以设置默认取消吗? MessageBoxResult result = MessageBox.Show (message, caption, Messag
我正在将第三方基于 C 的 SDK 集成到我的 .NET 应用程序中。该应用程序将作为 Windows 服务在服务器上运行,因此它不应以任何方式与用户交互。 不幸的是,在某些错误情况下,它坚持调用 M
我有一个程序可以让用户在 2 个值之间进行选择。为此,我想打开一个带有 2 个按钮(确定、取消)和一个可供选择或写入值的字段的框。就像 QMessageBox 一样,可以填写/选择数据。我可以创建一个
如何将自定义按钮添加到 WPF 中现有的 MessageBox 中?除了通常的“确定”和“取消”按钮之外,我还需要添加 3 个按钮并处理它们的事件。 最佳答案 简短回答:不,这是不可能的,您需要编写一
我在 Windows 窗体上有几个组框,其中包含复选框、数字选择器和组合框。如果未选中该复选框,我希望禁用其他元素。我已经禁用了除加载复选框之外的所有内容,然后在 CheckedChanged 事件上
我有一个 c# 程序,正在尝试使用特定字符串(普通字符串,没什么特别的)调用 messageBox,并且当到达要与字符串连接的变量时,它显然会停止连接。代码: string first = userI
我一直认为 MessageBoxes 有点像断点——它们会阻止程序执行,直到用户单击“确定”。但是,我刚刚发现这是不准确的,我正试图弄清楚 MessageBoxes 何时会和不会停止执行。 通过 SO
我正在尝试显示一条简单的消息,我过去可能已经这样做过数千次,而现在……完整的文本字符串没有显示在 MessageBox 中。我没有做任何不同的事情,所以我没有看到问题。这是我的代码: if (Mess
我在使用模态消息框时遇到问题。 情况是这样的 用户从表单中选择 xx 出现消息框 用户打开嵌入式软件键盘(内置键盘,来自设备) 用户关闭键盘 MessageBox 失去焦点(怎么会?它应该是模态的!)
我正在使用 Kinect 开发一个使用 C# 和 WPF 的图像查看应用程序。当用户将双手放在头顶时,我会显示一个 Messagebox 询问用户是否真的想退出: //Quit if both
当我点击回车按钮时,显示MessageBox。当我像往常一样再次单击输入按钮时,我希望 MessageBox 关闭。问题是 - 它没有焦点,但 TextBox 有,当我单击输入按钮时 _textBox
我正在尝试找到一种从线程内部调用 MessageBox 的方法。但是我发现的每一段代码/示例都不起作用。有人可以用尽可能少的代码行以最简单、最简单的方式详细说明解决方案/示例吗? 到目前为止,这是我的
我在如下启动的 WPF 应用程序中有一个简单的消息框: private void Button_Click(object sender, RoutedEventArgs e) { Message
我是一名优秀的程序员,十分优秀!