Sorry for my poor English first. And my question is , if I use the code which change the height of the line ,I could not click the delete button to delete one line form the table. I don't known why, please help me !!
The following is the complete demo code :
........................................................
public class ww {
private Table table;
protected Shell shell;
private Composite composite;
/**
* Launch the application
* @param args
*/
public static void main(
String[] args) {
try {
ww window = new ww();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
/**
* Create contents of the window
*/
protected void createContents() {
shell = new Shell();
shell.setSize(471, 500);
shell.setText("SWT Application");
composite = new Composite(shell,SWT.NONE);
composite.setSize(471, 500);
final Group group = new Group(composite, SWT.NONE);
group.setText("Edit");
group.setBounds(48, 297, 383, 145);
table = new Table(group,SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setBounds(10, 24, 373, 121);
String[] tableHeader = { "Num", " type ", " X ", " Y " };
for (int i = 0; i < tableHeader.length; i++) {
TableColumn tc = new TableColumn(table, SWT.NONE);
tc.setText(tableHeader);
tc.setMoveable(true);
}
for (int i = 0, n = table.getColumnCount(); i < n; i++) {
table.getColumn(i).pack();
}
//These code used to change the height of the line, error occours here。。。
// table.addListener(SWT.MeasureItem, new Listener() {
// public void handleEvent(Event event) {
// event.height = (int)(event.gc.getFontMetrics().getHeight() * 1.5);
// }
// });
final Button button = new Button(composite, SWT.NONE);
button.setText("+");
button.setBounds(263, 252, 48, 22);
button.addSelectionListener(new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e) {}
public void widgetSelected(SelectionEvent e) {
TableItem item = new TableItem(table,SWT.NONE);
item.setText(new String[] { 1 +"", "", "", "" });
}
});
final Button button_5 = new Button(composite, SWT.NONE);
button_5.setText("-");
button_5.setBounds(340, 249, 48, 28);
button_5.addSelectionListener(new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e) {}
public void widgetSelected(SelectionEvent e) {
if(table.getSelectionIndex() >=0)
{
table.clear(table.getSelectionIndex()); //clean the value
table.remove(table.getSelectionIndex());//delete the line。
}
}
});
}
}
This problem confused my for a long time. Thank you very much for answering..
