首页 > 代码库 > JTable
JTable
final Table table = new Table(parent, SWT.NONE | SWT.FULL_SELECTION); final GridData gd = new GridData(SWT.LEFT, SWT.TOP, false, true); gd.heightHint = 100; table.setLayoutData(gd); table.setHeaderVisible(true); table.setLinesVisible(true); final TableColumn tcCondition = new TableColumn(table, SWT.None); final TableColumn tcUserValue = http://www.mamicode.com/new TableColumn(table, SWT.None);"条件"); tcCondition.setWidth(80); tcUserValue.setText("枚举值"); tcUserValue.setWidth(80); tcUserColor.setText("颜色"); tcUserColor.setWidth(80); table.addListener(SWT.MouseDoubleClick, new Listener() { int editColumnIndex = -1; @Override public void handleEvent(final Event e) { final Point point = new Point(e.x, e.y); final TableItem tableItem = table.getItem(point); if (tableItem == null) { return; } for (int i = 0; i < 3; i++) { final Rectangle r = tableItem.getBounds(i); if (r.contains(point)) { editColumnIndex = i; final TableEditor editor = new TableEditor(table); final Control oldEditor = editor.getEditor(); if (oldEditor != null) { oldEditor.dispose(); } final Text text = new Text(table, SWT.NONE); text.computeSize(SWT.DEFAULT, table.getItemHeight()); editor.grabHorizontal = true; editor.minimumHeight = text.getSize().y; editor.minimumWidth = text.getSize().x; editor.setEditor(text, tableItem, editColumnIndex); text.setText(tableItem.getText(editColumnIndex)); text.forceFocus(); text.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { editor.getItem().setText(editColumnIndex, text.getText()); } }); text.addFocusListener(new FocusListener() { @Override public void focusGained(final FocusEvent e) { // TODO Auto-generated method stub } @Override public void focusLost(final FocusEvent e) { text.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); text.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); } }); } } } });
JTable
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。