gpt4 book ai didi

java - JFace 对话框按钮栏出现故障

转载 作者:行者123 更新时间:2023-12-02 05:00:32 30 4
gpt4 key购买 nike

如图所示,对话框打开时按钮栏有时无法正确显示。我认为由于我必须为 DefaultTableModel 嵌入 awt 框架,因此产生了一些布局问题。

Glitch with the Button bar

有什么办法可以解决这个问题吗?或者我应该使用 jface checkboxtableviewer,但我找不到一个很好的例子。

public class FunctionMaskDialog extends Dialog implements TableModelListener{

private Boolean[] functionChecked;
private JTable table;
private Table table_1;
/**
* Constructor Create the dialog.
*
* @param parentShell
*/
public FunctionMaskDialog(Shell parentShell) {
super(parentShell);
}

@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText("Function Mask");
}

/**
* Create contents of the button bar.
*
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {

createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
getButton(IDialogConstants.OK_ID).addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {
setFunctionCheckedArray();
}
});

createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);

getButton(IDialogConstants.CANCEL_ID).addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
}

/**
* Create contents of the dialog.
*
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {

Composite container = new Composite(parent, SWT.EMBEDDED);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Frame frame = SWT_AWT.new_Frame(container);
frame.setLayout(null);
frame.setBackground(new Color(240, 240, 240));

JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(30, 30, 494, 400);


// Table
table = new JTable();
scrollPane.setViewportView(table);

this.createFunctionTaskTable(table);

frame.add(scrollPane);

return container;
}



/**
* Return the initial size of the dialog.
*/
@Override
protected Point getInitialSize() {
return new Point(600, 530);
}


private void createFunctionTaskTable(JTable table){

// Model for Table
@SuppressWarnings("serial")
DefaultTableModel model = new DefaultTableModel() {

public Class<?> getColumnClass(int column) {
switch (column) {
case 0:
return Boolean.class;
case 1:
return String.class;
default:
return String.class;
}
}

@Override
public boolean isCellEditable(int row, int column) {
if (column == 1)
return false;
else
return true;
}
};

table.setModel(model);

model.addColumn("Select");
model.addColumn("Function Name");

table.getColumnModel().getColumn(0).setPreferredWidth(94);
table.getColumnModel().getColumn(1).setPreferredWidth(400);


// initialize chked array according to the size of task list.
functionChecked = GanttFrame.getFunctionCheckedArray();

model.addTableModelListener(this);


// Data Rows
for (int i = 0; i < GanttFrame.getFunctionTaskList().size(); i++) {
model.addRow(new Object[0]);
model.setValueAt(functionChecked[i], i, 0);
model.setValueAt(GanttFrame.getFunctionTaskList().get(i).getTaskName(), i, 1); // initialize the function names
}

}

private void setFunctionCheckedArray(){

Boolean[] tempArray = functionChecked;

for (int i = 0; i < table.getRowCount(); i++) {
functionChecked[i] = Boolean.valueOf(table.getValueAt(i, 0).toString());
}

if (!tempArray.equals(functionChecked)){
GanttFrame.setFunctionCheckedArray(functionChecked);
}
}

@Override
public void tableChanged(TableModelEvent event) {

DefaultTableModel model = (DefaultTableModel)event.getSource();

if (event.getColumn() == 0){

if (event.getFirstRow() == 0){
}
}



}
}

最佳答案

SWT/AWT 桥不是您想要自愿使用的东西。除非您确实必须在 SWT 应用程序中使用现有的 AWT UI,否则您应该远离它。这个article揭示更多细节。

如果可以的话,请使用CheckboxTableViewer。要创建实例,请使用 CheckboxTableViewer#newCheckList()。要在选中或取消选中某个元素时收到通知,请添加一个 ICheckStateListenerJavaDoc列出了查询和操作其元素的检查状态的所有方法。有关 TableViewer 的一般介绍,只需在网络上搜索“JFace TableViewer”,您就会找到大量资源。

关于java - JFace 对话框按钮栏出现故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326840/

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