📄 examplegui.java
字号:
}
);
}
/**
* Constructs a simple text table.
* The table model is directly created from the interface KTableModel.
* Editors are KTableCellEditorText and KTableCellEditorCombo.<p>
* NOTE that this shows how to set an Excel-like mouse cursor for the
* KTable. If setCursor() is used, the cursor is not preserved and will
* be swiched back to the default cursor when a resize cursor or something
* else is shown.
*/
private static void createTextTable(TabFolder tabFolder) {
TabItem item1 = new TabItem(tabFolder, SWT.NONE);
item1.setText("Text Table");
Composite comp1 = new Composite(tabFolder, SWT.NONE);
item1.setControl(comp1);
comp1.setLayout(new FillLayout());
final KTable table = new KTable(comp1, SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL
| SWT.H_SCROLL | SWTX.FILL_WITH_LASTCOL | SWTX.EDIT_ON_KEY);
table.setModel(new TextModelExample());
table.addCellSelectionListener(
new KTableCellSelectionListener()
{
public void cellSelected(int col, int row, int statemask) {
System.out.println("Cell ["+col+";"+row+"] selected.");
}
public void fixedCellSelected(int col, int row, int statemask) {
System.out.println("Header ["+col+";"+row+"] selected.");
}
}
);
table.addCellResizeListener(
new KTableCellResizeListener()
{
public void columnResized(int col, int newWidth) {
System.out.println("Column "+col+" resized to "+newWidth);
}
public void rowResized(int row, int newHeight) {
System.out.println("Row "+row+" resized to "+newHeight);
}
}
);
/**
* Set Excel-like table cursors
*/
if ( SWT.getPlatform().equals("win32") ) {
// Cross
Image crossCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/cross_win32.gif");
// Row Resize
Image row_resizeCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/row_resize_win32.gif");
// Column Resize
Image column_resizeCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/column_resize_win32.gif");
// we set the hotspot to the center, so calculate the number of pixels from hotspot to lower border:
Rectangle crossBound = crossCursor.getBounds();
Rectangle rowresizeBound = row_resizeCursor.getBounds();
Rectangle columnresizeBound = column_resizeCursor.getBounds();
Point crossSize = new Point(crossBound.width/2, crossBound.height/2);
Point rowresizeSize = new Point(rowresizeBound.width/2, rowresizeBound.height/2);
Point columnresizeSize = new Point(columnresizeBound.width/2, columnresizeBound.height/2);
table.setDefaultCursor(new Cursor(table.getDisplay(), crossCursor.getImageData(), crossSize.x, crossSize.y), crossSize);
table.setDefaultRowResizeCursor(new Cursor(table.getDisplay(), row_resizeCursor.getImageData(), rowresizeSize.x, rowresizeSize.y));
table.setDefaultColumnResizeCursor(new Cursor(table.getDisplay(), column_resizeCursor.getImageData(), columnresizeSize.x, columnresizeSize.y));
} else {
// Cross
Image crossCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/cross.gif");
Image crossCursor_mask = SWTX.loadImageResource(table.getDisplay(), "/icons/cross_mask.gif");
// Row Resize
Image row_resizeCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/row_resize.gif");
Image row_resizeCursor_mask = SWTX.loadImageResource(table.getDisplay(), "/icons/row_resize_mask.gif");
// Column Resize
Image column_resizeCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/column_resize.gif");
Image column_resizeCursor_mask = SWTX.loadImageResource(table.getDisplay(), "/icons/column_resize_mask.gif");
// we set the hotspot to the center, so calculate the number of pixels from hotspot to lower border:
Rectangle crossBound = crossCursor.getBounds();
Rectangle rowresizeBound = row_resizeCursor.getBounds();
Rectangle columnresizeBound = column_resizeCursor.getBounds();
Point crossSize = new Point(crossBound.width/2, crossBound.height/2);
Point rowresizeSize = new Point(rowresizeBound.width/2, rowresizeBound.height/2);
Point columnresizeSize = new Point(columnresizeBound.width/2, columnresizeBound.height/2);
table.setDefaultCursor(new Cursor(table.getDisplay(), crossCursor_mask.getImageData(), crossCursor.getImageData(), crossSize.x, crossSize.y), crossSize);
table.setDefaultRowResizeCursor(new Cursor(table.getDisplay(), row_resizeCursor_mask.getImageData(), row_resizeCursor.getImageData(), rowresizeSize.x, rowresizeSize.y));
table.setDefaultColumnResizeCursor(new Cursor(table.getDisplay(), column_resizeCursor_mask.getImageData(), column_resizeCursor.getImageData(), columnresizeSize.x, columnresizeSize.y));
}
}
/**
* Constructs a simple text table that demonstrates the creation of a sorted table.
* <p>
* Note that the only thing that is necessary to make the table itself sortable is
* subclassing the <code>KTableSortedModel</code>. Then the sort() method is available
* to custom handlers.<p>
* This shows how to register some common listeners that make the table behave in an
* often seen way.
*/
private static void createSortableTable(TabFolder tabFolder) {
TabItem item1 = new TabItem(tabFolder, SWT.NONE);
item1.setText("Sortable Table");
Composite comp1 = new Composite(tabFolder, SWT.NONE);
item1.setControl(comp1);
comp1.setLayout(new FillLayout());
final KTable table = new KTable(comp1, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
final KTableSortedModel model = new SortableModelExample();
table.setModel(model);
table.addCellSelectionListener(
new KTableCellSelectionListener()
{
public void cellSelected(int col, int row, int statemask) {
// the idea is to map the row index back to the model index since the given row index
// changes when sorting is done.
int modelRow = model.mapRowIndexToModel(row);
System.out.println("Cell ["+col+";"+row+"] selected. - Model row: "+modelRow);
}
public void fixedCellSelected(int col, int row, int statemask) {
System.out.println("Header ["+col+";"+row+"] selected.");
}
}
);
// implement resorting when the user clicks on the table header:
table.addCellSelectionListener(new KTableSortOnClick(table,
new SortComparatorExample(model, -1, KTableSortComparator.SORT_NONE)));
table.addCellResizeListener(
new KTableCellResizeListener()
{
public void columnResized(int col, int newWidth) {
System.out.println("Column "+col+" resized to "+newWidth);
}
public void rowResized(int row, int newHeight) {
System.out.println("Row "+row+" resized to "+newHeight);
}
}
);
/**
* Set Excel-like table cursors
*/
if ( SWT.getPlatform().equals("win32") ) {
// Cross
Image crossCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/cross_win32.gif");
// Row Resize
Image row_resizeCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/row_resize_win32.gif");
// Column Resize
Image column_resizeCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/column_resize_win32.gif");
// we set the hotspot to the center, so calculate the number of pixels from hotspot to lower border:
Rectangle crossBound = crossCursor.getBounds();
Rectangle rowresizeBound = row_resizeCursor.getBounds();
Rectangle columnresizeBound = column_resizeCursor.getBounds();
Point crossSize = new Point(crossBound.width/2, crossBound.height/2);
Point rowresizeSize = new Point(rowresizeBound.width/2, rowresizeBound.height/2);
Point columnresizeSize = new Point(columnresizeBound.width/2, columnresizeBound.height/2);
table.setDefaultCursor(new Cursor(table.getDisplay(), crossCursor.getImageData(), crossSize.x, crossSize.y), crossSize);
table.setDefaultRowResizeCursor(new Cursor(table.getDisplay(), row_resizeCursor.getImageData(), rowresizeSize.x, rowresizeSize.y));
table.setDefaultColumnResizeCursor(new Cursor(table.getDisplay(), column_resizeCursor.getImageData(), columnresizeSize.x, columnresizeSize.y));
} else {
// Cross
Image crossCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/cross.gif");
Image crossCursor_mask = SWTX.loadImageResource(table.getDisplay(), "/icons/cross_mask.gif");
// Row Resize
Image row_resizeCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/row_resize.gif");
Image row_resizeCursor_mask = SWTX.loadImageResource(table.getDisplay(), "/icons/row_resize_mask.gif");
// Column Resize
Image column_resizeCursor = SWTX.loadImageResource(table.getDisplay(), "/icons/column_resize.gif");
Image column_resizeCursor_mask = SWTX.loadImageResource(table.getDisplay(), "/icons/column_resize_mask.gif");
// we set the hotspot to the center, so calculate the number of pixels from hotspot to lower border:
Rectangle crossBound = crossCursor.getBounds();
Rectangle rowresizeBound = row_resizeCursor.getBounds();
Rectangle columnresizeBound = column_resizeCursor.getBounds();
Point crossSize = new Point(crossBound.width/2, crossBound.height/2);
Point rowresizeSize = new Point(rowresizeBound.width/2, rowresizeBound.height/2);
Point columnresizeSize = new Point(columnresizeBound.width/2, columnresizeBound.height/2);
table.setDefaultCursor(new Cursor(table.getDisplay(), crossCursor_mask.getImageData(), crossCursor.getImageData(), crossSize.x, crossSize.y), crossSize);
table.setDefaultRowResizeCursor(new Cursor(table.getDisplay(), row_resizeCursor_mask.getImageData(), row_resizeCursor.getImageData(), rowresizeSize.x, rowresizeSize.y));
table.setDefaultColumnResizeCursor(new Cursor(table.getDisplay(), column_resizeCursor_mask.getImageData(), column_resizeCursor.getImageData(), columnresizeSize.x, columnresizeSize.y));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -