Java 如何构建文本和在SWT中查找文件的选项
我想知道是否可以在Java 如何构建文本和在SWT中查找文件的选项,java,swt,Java,Swt,我想知道是否可以在文本附近构建一个文本按钮,当我按下按钮时,它会打开一个新窗口,从我的计算机中选择一个文件(如浏览按钮) 有可能在SWT中完成吗?您有什么例子吗?只需使用文件对话框选择文件并将结果保存在文本中即可。使用按钮和侦听器到SWT。选择打开文件对话框: public static void main(String[] args) { Display display = Display.getDefault(); final Shell shell = new Shell(
文本
附近构建一个文本
按钮,当我按下按钮时,它会打开一个新窗口,从我的计算机中选择一个文件(如浏览按钮)
有可能在SWT中完成吗?您有什么例子吗?只需使用
文件对话框
选择文件并将结果保存在文本中即可。使用按钮
和侦听器
到SWT。选择
打开文件对话框
:
public static void main(String[] args)
{
Display display = Display.getDefault();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new FillLayout(SWT.VERTICAL));
final Text path = new Text(shell, SWT.BORDER);
Button fileChooser = new Button(shell, SWT.PUSH);
fileChooser.setText("Browse...");
fileChooser.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
FileDialog dialog = new FileDialog(shell);
String filePath = dialog.open();
if(filePath != null)
path.setText(filePath);
}
});
shell.pack();
Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
shell.setSize(400, size.y);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
只需使用文件对话框
选择文件并将结果保存在文本中
。使用按钮
和侦听器
到SWT。选择
打开文件对话框
:
public static void main(String[] args)
{
Display display = Display.getDefault();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new FillLayout(SWT.VERTICAL));
final Text path = new Text(shell, SWT.BORDER);
Button fileChooser = new Button(shell, SWT.PUSH);
fileChooser.setText("Browse...");
fileChooser.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
FileDialog dialog = new FileDialog(shell);
String filePath = dialog.open();
if(filePath != null)
path.setText(filePath);
}
});
shell.pack();
Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
shell.setSize(400, size.y);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
只需使用文件对话框
选择文件并将结果保存在文本中
。使用按钮
和侦听器
到SWT。选择
打开文件对话框
:
public static void main(String[] args)
{
Display display = Display.getDefault();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new FillLayout(SWT.VERTICAL));
final Text path = new Text(shell, SWT.BORDER);
Button fileChooser = new Button(shell, SWT.PUSH);
fileChooser.setText("Browse...");
fileChooser.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
FileDialog dialog = new FileDialog(shell);
String filePath = dialog.open();
if(filePath != null)
path.setText(filePath);
}
});
shell.pack();
Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
shell.setSize(400, size.y);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
只需使用文件对话框
选择文件并将结果保存在文本中
。使用按钮
和侦听器
到SWT。选择
打开文件对话框
:
public static void main(String[] args)
{
Display display = Display.getDefault();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new FillLayout(SWT.VERTICAL));
final Text path = new Text(shell, SWT.BORDER);
Button fileChooser = new Button(shell, SWT.PUSH);
fileChooser.setText("Browse...");
fileChooser.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event arg0)
{
FileDialog dialog = new FileDialog(shell);
String filePath = dialog.open();
if(filePath != null)
path.setText(filePath);
}
});
shell.pack();
Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
shell.setSize(400, size.y);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
如果您不委派活动,为什么不在按钮上使用SelectionAdapter
?还是只是一种习惯?顺便说一句,10公里里程碑@GGrec干杯。这是一种习惯,尽管我看不出有什么区别,因为SelectionAdapter
的widgetSelected
方法也有一个不会使用/委派的事件。如果你不委派事件,为什么不在按钮上使用SelectionAdapter
?还是只是一种习惯?顺便说一句,10公里里程碑@GGrec干杯。这是一种习惯,尽管我看不出有什么区别,因为SelectionAdapter
的widgetSelected
方法也有一个不会使用/委派的事件。如果你不委派事件,为什么不在按钮上使用SelectionAdapter
?还是只是一种习惯?顺便说一句,10公里里程碑@GGrec干杯。这是一种习惯,尽管我看不出有什么区别,因为SelectionAdapter
的widgetSelected
方法也有一个不会使用/委派的事件。如果你不委派事件,为什么不在按钮上使用SelectionAdapter
?还是只是一种习惯?顺便说一句,10公里里程碑@GGrec干杯。这是一种习惯,尽管我看不出有什么区别,因为SelectionAdapter
的widgetSelected
方法也有一个不会使用/委派的事件。