List of usage examples for org.eclipse.swt.widgets Label pack
public void pack()
From source file:Snippet34.java
public static void main(String[] args) { Display display = new Display(); Image image = new Image(display, 16, 16); Color color = display.getSystemColor(SWT.COLOR_RED); GC gc = new GC(image); gc.setBackground(color);//from www . j a va 2s . c o m gc.fillRectangle(image.getBounds()); gc.dispose(); Shell shell = new Shell(display); Label label = new Label(shell, SWT.BORDER); label.setImage(image); label.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet249.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 249"); Rectangle clientArea = shell.getClientArea(); shell.setBounds(clientArea.x + 10, clientArea.y + 10, 300, 200); // create the composite that the pages will share final Composite contentPanel = new Composite(shell, SWT.BORDER); contentPanel.setBounds(clientArea.x + 100, clientArea.y + 10, 190, 90); final StackLayout layout = new StackLayout(); contentPanel.setLayout(layout);// w w w . ja va2s . c o m // create the first page's content final Composite page0 = new Composite(contentPanel, SWT.NONE); page0.setLayout(new RowLayout()); Label label = new Label(page0, SWT.NONE); label.setText("Label on page 1"); label.pack(); // create the second page's content final Composite page1 = new Composite(contentPanel, SWT.NONE); page1.setLayout(new RowLayout()); Button button = new Button(page1, SWT.NONE); button.setText("Button on page 2"); button.pack(); // create the button that will switch between the pages Button pageButton = new Button(shell, SWT.PUSH); pageButton.setText("Push"); pageButton.setBounds(clientArea.x + 10, clientArea.y + 10, 80, 25); pageButton.addListener(SWT.Selection, event -> { pageNum = ++pageNum % 2; layout.topControl = pageNum == 0 ? page0 : page1; contentPanel.layout(); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:StackLayoutSwitchComposites.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 300, 200);/*from w w w . j a va 2 s .co m*/ // create the composite that the pages will share final Composite contentPanel = new Composite(shell, SWT.BORDER); contentPanel.setBounds(100, 10, 190, 90); final StackLayout layout = new StackLayout(); contentPanel.setLayout(layout); // create the first page's content final Composite page0 = new Composite(contentPanel, SWT.NONE); page0.setLayout(new RowLayout()); Label label = new Label(page0, SWT.NONE); label.setText("Label on page 1"); label.pack(); // create the second page's content final Composite page1 = new Composite(contentPanel, SWT.NONE); page1.setLayout(new RowLayout()); Button button = new Button(page1, SWT.NONE); button.setText("Button on page 2"); button.pack(); // create the button that will switch between the pages Button pageButton = new Button(shell, SWT.PUSH); pageButton.setText("Push"); pageButton.setBounds(10, 10, 80, 25); pageButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { pageNum = ++pageNum % 2; layout.topControl = pageNum == 0 ? page0 : page1; contentPanel.layout(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet34.java
public static void main(String[] args) { Display display = new Display(); Image image = new Image(display, 16, 16); Color color = display.getSystemColor(SWT.COLOR_RED); GC gc = new GC(image); gc.setBackground(color);/*from w ww.java2s . c o m*/ gc.fillRectangle(image.getBounds()); gc.dispose(); Shell shell = new Shell(display); shell.setText("Snippet 34"); Label label = new Label(shell, SWT.BORDER); Rectangle clientArea = shell.getClientArea(); label.setLocation(clientArea.x, clientArea.y); label.setImage(image); label.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:Snippet32.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Label label = new Label(shell, SWT.NONE); label.setText("Can't find icon for .bmp"); Image image = null;//from w ww . ja v a 2 s. c o m Program p = Program.findProgram(".bmp"); if (p != null) { ImageData data = p.getImageData(); if (data != null) { image = new Image(display, data); label.setImage(image); } } label.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet32.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 32"); Label label = new Label(shell, SWT.NONE); label.setText("Can't find icon for .bmp"); Image image = null;//from w w w. j ava 2 s . co m Program p = Program.findProgram(".bmp"); if (p != null) { ImageData data = p.getImageData(); if (data != null) { image = new Image(display, data); label.setImage(image); } } label.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet276.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 276"); shell.setBounds(200, 200, 400, 400); Label label = new Label(shell, SWT.NONE); label.setText("click in shell to print display-relative coordinate"); Listener listener = event -> {/*from w w w. j a v a 2 s.c o m*/ Point point = new Point(event.x, event.y); System.out.println(display.map((Control) event.widget, null, point)); }; shell.addListener(SWT.MouseDown, listener); label.addListener(SWT.MouseDown, listener); Rectangle clientArea = shell.getClientArea(); label.setLocation(clientArea.x, clientArea.y); label.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:SystemFileIconLoad.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Label label = new Label(shell, SWT.NONE); Image image = null;// www .jav a2 s.co m Program p = Program.findProgram(".txt"); ImageData data = p.getImageData(); image = new Image(display, data); label.setImage(image); p = Program.findProgram(".bmp"); data = p.getImageData(); image = new Image(display, data); label = new Label(shell, SWT.NONE); label.setImage(image); p = Program.findProgram(".doc"); data = p.getImageData(); image = new Image(display, data); label = new Label(shell, SWT.NONE); label.setImage(image); label.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }
From source file:HelloWorld3.java
public Shell open(Display display) { final Shell shell = new Shell(display); final Label label = new Label(shell, SWT.CENTER); label.setText("Hello_world"); label.pack(); shell.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { label.setBounds(shell.getClientArea()); }/*from w ww . j av a 2 s . c om*/ }); shell.pack(); shell.open(); return shell; }
From source file:org.eclipse.swt.examples.helloworld.HelloWorld3.java
public Shell open(Display display) { final Shell shell = new Shell(display); final Label label = new Label(shell, SWT.CENTER); label.setText(resHello.getString("Hello_world")); label.pack(); shell.addControlListener(//from www. jav a 2 s . c o m ControlListener.controlResizedAdapter(e -> label.setBounds(shell.getClientArea()))); shell.pack(); shell.open(); return shell; }