Adding a force frame to a SWT table
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. Custom. tableeditor;
Import org. Eclipse. SWT. Events. focusadapter;
Import org. Eclipse. SWT. Events. focusevent;
Import org. Eclipse. SWT. Events. selectionadapter;
Import org. Eclipse. SWT. Events. selectionevent;
Import org. Eclipse. SWT. Widgets. display;
Import org. Eclipse. SWT. Widgets. shell;
Import org. Eclipse. SWT. Widgets. Table;
Import org. Eclipse. SWT. Widgets. tablecolumn;
Import org. Eclipse. SWT. Widgets. tableitem;
Import org. Eclipse. SWT. Widgets. text;
Public class testcheck2 {
Public static void main (string [] ARGs ){
Display display = New Display ();
Final shell = new shell (Display );
Shell. settext ("AB ");
Shell. setlayout (null );
Final table = new table (shell, SWT. Border | SWT. full_selection );
Table. setbounds (0, 0,268,106 );
String [] Cols = {"A", "B "};
For (INT I = 0; I <cols. length; I ++ ){
Tablecolumn Col = new tablecolumn (table, SWT. Left );
Col. settext (Cols [I]);
Col. setwidth (100 );
}
Table. setheadervisible (true );
Table. setlinesvisible (true );
Tableitem Item1 = new tableitem (table, SWT. null );
Item1.settext (0, "name ");
Item1.settext (1, "fei ");
Tableitem item2 = new tableitem (table, SWT. null );
Item2.settext (0, "e-mail ");
Item2.settext (1, "fei@dhc.com.cn ");
Final tableeditor = new tableeditor (table );
Tableeditor. grabhorizontal = true;
Table. addselectionlistener (New selectionadapter (){
Private Static final int edit_column = 1;
Public void widgetselected (selectionevent e ){
Int Index = table. getselectionindex ();
If (Index =-1 ){
Return;
}
Table. setselection (New int [0]);
Tableitem item = table. getitem (INDEX );
Final text = new text (table, SWT. None );
Text. settext (item. gettext (edit_column ));
Text. addfocuslistener (New focusadapter (){
Public void focuslost (focusevent e ){
Tableitem item = tableeditor. getitem ();
Item. settext (edit_column, text. gettext ());
Text. Dispose ();
}
});
Tableeditor. seteditor (text, item, edit_column );
Text. setfocus ();
Text. selectall ();
}
});
Shell. setsize (273,136 );
Shell. open ();
While (! Shell. isdisposed ()){
If (! Display. readanddispatch ()){
Display. Sleep ();
}
}
Display. Dispose ();
}
}