The code is as follows:
Dropdownandsimple.java
Copy Code code as follows:
Package Swt_jface.demo3;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.layout.RowLayout;
Import Org.eclipse.swt.widgets.Combo;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Shell;
public class Dropdownandsimple {
Display display = new display ();
Shell shell = new shell (display);
Public Dropdownandsimple () {
Rowlayout rowlayout = new Rowlayout ();
rowlayout.spacing = 15;
Rowlayout.marginwidth = 15;
Rowlayout.marginheight = 15;
Shell.setlayout (rowlayout);
Combo Combodropdown = new Combo (Shell, SWT. Drop_down | Swt. BORDER);
Combo combosimple = new Combo (Shell, SWT. Simple | Swt. BORDER);
for (int i=0; i<3; i++) {
Combodropdown.add ("item" + i);
Combosimple.add ("item" + i);
}
Shell.pack ();
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Dropdownandsimple ();
}
}
Samplecombo.java
Copy Code code as follows:
Package Swt_jface.demo3;
Import Java.util.Arrays;
Import Org.eclipse.swt.SWT;
Import org.eclipse.swt.events.SelectionEvent;
Import Org.eclipse.swt.events.SelectionListener;
Import Org.eclipse.swt.layout.GridLayout;
Import Org.eclipse.swt.widgets.Combo;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Label;
Import Org.eclipse.swt.widgets.Shell;
public class Samplecombo {
Display display = new display ();
Shell shell = new shell (display);
Public Samplecombo () {
Shell.setlayout (New GridLayout (2, false));
(New Label (Shell, SWT.) NULL)). SetText ("Select your favorite programming language:");
Final Ccombo combo = new Ccombo (Shell, SWT. FLAT);
Final Combo Combo = new Combo (Shell, SWT. NULL);
String[] languages = new string[]{"Java," "C", "C + +", "SmallTalk"};
Arrays.sort (languages);
for (int i=0; i<languages.length; i++)
Combo.add (Languages[i]);
Combo.add ("Perl", 5);
Combo.setitem (5, "Perl");
Combo.addselectionlistener (New Selectionlistener () {
public void widgetselected (Selectionevent e) {
SYSTEM.OUT.PRINTLN ("Selected index:" + combo.getselectionindex () + ", Selected item:" + Combo.getitem (combo.getselectio Nindex ()) + ", text content in the text field:" + Combo.gettext ());
}
public void widgetdefaultselected (Selectionevent e) {
System.out.println ("Default Selected index:" + combo.getselectionindex () + ", Selected item:" + (Combo.getselectionindex () = =-1? "<null>": Combo.getitem (Combo.getselectionindex ()) + ", text content in the text field:" + Combo.gettext ());
String text = Combo.gettext ();
if (Combo.indexof (text) < 0) {//Not in the list yet.
Combo.add (text);
Re-sort
string[] items = Combo.getitems ();
Arrays.sort (items);
Combo.setitems (items);
}
}
});
Shell.pack ();
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Samplecombo ();
}
}
Samplelist.java
Copy Code code as follows:
Package Swt_jface.demo3;
Import Org.eclipse.swt.SWT;
Import org.eclipse.swt.events.SelectionEvent;
Import Org.eclipse.swt.events.SelectionListener;
Import Org.eclipse.swt.layout.RowLayout;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Label;
Import org.eclipse.swt.widgets.List;
Import Org.eclipse.swt.widgets.Shell;
public class Samplelist {
Display display = new display ();
Shell shell = new shell (display);
Public Samplelist () {
Rowlayout rowlayout = new Rowlayout ();
Shell.setlayout (rowlayout);
(New Label (Shell, SWT.) NULL)). SetText ("What programming languages are in?");
Final list = new List (shell, SWT. Single | Swt. BORDER | Swt. V_scroll);
String[] languages = new string[]{"Java," "C", "C + +", "SmallTalk"};
for (int i=0; i<languages.length; i++)
List.add (Languages[i]);
List.addselectionlistener (New Selectionlistener () {
public void widgetselected (Selectionevent e) {
System.err.println (List.getselectionindex ());
int[] Indices = list.getselectionindices ();
string[] items = list.getselection ();
StringBuffer sb = new StringBuffer ("Selected Indices:");
for (int i=0 i < indices.length; i++) {
Sb.append (Indices[i]);
Sb.append ("(");
Sb.append (Items[i]);
Sb.append (")");
if (i = = indices.length-1)
Sb.append ('. ');
Else
Sb.append (",");
}
System.out.println (Sb.tostring ());
}
public void widgetdefaultselected (Selectionevent e) {
int[] Indices = list.getselectionindices ();
string[] items = list.getselection ();
StringBuffer sb = new StringBuffer ("Default Selected indices:");
for (int i=0 i < indices.length; i++) {
Sb.append (Indices[i]);
Sb.append ("(");
Sb.append (Items[i]);
Sb.append (")");
if (i = = indices.length-1)
Sb.append ('. ');
Else
Sb.append (",");
}
System.out.println (Sb.tostring ());
}
});
List.selectall ();
List.select (1);
Shell.pack ();
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Samplelist ();
}
}
Singlemultilists.java
Copy Code code as follows:
Package Swt_jface.demo3;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.layout.GridLayout;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Label;
Import org.eclipse.swt.widgets.List;
Import Org.eclipse.swt.widgets.Shell;
public class Singlemultilists {
Display display = new display ();
Shell shell = new shell (display);
Public singlemultilists () {
GridLayout GridLayout = new GridLayout (2, true);
Shell.setlayout (gridLayout);
(New Label (Shell, SWT.) NULL)). SetText ("single");
(New Label (Shell, SWT.) NULL)). SetText ("MULTI");
List singleselectlist = new List (shell, SWT. BORDER);
List mutliselectlist = new List (shell, SWT. MULTI | Swt. BORDER);
string[] items = new string[]{"Item 1", "Item 2", "Item 3", "Item 4"};
for (int i=0; i<items.length; i++) {
Singleselectlist.add (Items[i]);
Mutliselectlist.add (Items[i]);
}
Shell.pack ();
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Singlemultilists ();
}
}
Current 1/2 page
12 Next read the full text