我正在使用最新的Mac OS X,我正在Gradle文件中创建一个GUI元素.我目前正在使用jdk1.7.0_55并且我已导入groovy.swing.SwingBuilder
,当我运行该项目时,我收到以下错误:
java.awt.AWTError:"找不到工具包:apple.awt.CToolkit
我已经尝试使用脚本作为无头服务器运行 System.setProperty('java.awt.headless', 'true')
我想有一个解决方案,我可以直接包含在Gradle项目文件中,而不是试图找出我的accesibilities.properties
文件中的内容(在特定系统上可能不存在,就像我的系统上没有).
此外,项目必须使用内部解决方案,不允许使用外部库.
非常感谢你对此事的任何帮助.
编辑:示例代码
gradle.taskGraph.whenReady { taskGraph ->
if(taskGraph.hasTask(':CustomApp:assembleRelease')) {
def pass = ''
if(System.console() == null) {
new SwingBuilder().edt { // Error occurs here.
dialog(modal: true,
alwaysOnTop: true,
resizable: false,
locationRelativeTo: null,
pack: true,
show: true
)
{
vbox {
label(text: "Enter password:")
input = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
pass = input.password;
dispose();
})
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有2个简单的数据库查询JTable
(客户端和服务器).
客户端具有查看记录,打印,保存PDF等所有功能.服务器自动刷新数据库记录到表,计时器为30秒.(尚未实现.)
我的问题是我可以将数据库记录显示到表而没有以下代码的问题.
PreparedStatement pst = conn.prepareStatement("SQL");
ResultSet rs = pst.ExecuteQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
Run Code Online (Sandbox Code Playgroud)
但我希望用上面的代码用计时器实现表的自动刷新.
例如,我将代码插入名为public void的方法中Update_Records()
.我该如何使用计时器调用方法每隔30秒将记录显示到表中?
如何在下面定义的表中添加标题?
import groovy.swing.SwingBuilder
data = [[first:'qwer', last:'asdf'],
[first:'zxcv', last:'tyui'],
[first:'ghjk', last:'bnm']]
swing = new SwingBuilder()
frame = swing.frame(title:'table test'){
table {
tableModel( list : data ) {
propertyColumn(header:'First Name', propertyName:'first')
propertyColumn(header:'last Name', propertyName:'last')
}
}
}
frame.pack()
frame.show()
Run Code Online (Sandbox Code Playgroud) 我使用Java Swing(Windows Builder Pro)为个人项目创建了一个GUI,它有一个JToolBar
.我在工具栏的按钮之间添加了分隔符.
JButton btnSave = new JButton("Save");
btnSave.setToolTipText("Save");
btnSave.setMnemonic('S');
btnSave.setIcon(new ImageIcon(Main.class.getResource("/org/dbhaskaran/resources/Save32.png")));
toolBar.add(btnSave);
toolBar.add(new JSeparator(SwingConstants.VERTICAL));
JButton btnDesign = new JButton("Design");
btnDesign.setIcon(new ImageIcon(Main.class.getResource("/org/dbhaskaran/resources/wizard32.png")));
toolBar.add(btnDesign);
toolBar.add(new JSeparator(SwingConstants.VERTICAL));
Run Code Online (Sandbox Code Playgroud)
JButtons
在添加分隔符后我的右边对齐了?我该如何解决?我试图使用groovy swing builder的fileChooser没有运气.当我从groovy网站复制以下示例时:
def openExcelDialog = SwingBuilder.fileChooser(dialogTitle:"Choose an excel file",
id:"openExcelDialog", fileSelectionMode : JFileChooser.FILES_ONLY,
//the file filter must show also directories, in order to be able to look into them
fileFilter: [getDescription: {-> "*.xls"}, accept:{file-> file ==~ /.*?\.xls/ || file.isDirectory() }] as FileFilter) {
Run Code Online (Sandbox Code Playgroud)
}
但是我收到了一条错误消息:
groovy.lang.MissingMethodException: No signature of method: static groovy.swing.SwingBuilder.fileChooser() is applicable for argument types: (java.util.LinkedHashMap, ConsoleScript19$_run_closure1) values
Run Code Online (Sandbox Code Playgroud)