Adding a force frame to a SWT table

Source: Internet
Author: User

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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.