Button yes = new Button("Yes"); yes.setBounds(0, 30, 30, 60);
import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.part.ViewPart; import org.eclipse.swt.widgets.Button; public class test extends ViewPart { public test() { // TODO Auto-generated constructor stub } @Override public void createPartControl(Composite parent) { // TODO Auto-generated method stub Composite comParent = new Composite(parent, SWT.NONE); Button button = new Button(comParent, SWT.NONE); button.setBounds(97, 97, 75, 25); button.setText("New Button"); } @Override public void setFocus() { // TODO Auto-generated method stub } }
public class GameGUI extends JPanel implements ActionListener { public Button drawCard = new Button("Draw Card"); public Image cheetah = null; public void createGui(JFrame p) { drawCard.addActionListener(this); drawCard.setBounds(20,30,80,30); p.add(drawCard); } @Override public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); if (cause == drawCard) { System.out.println("Ay"); } } @Override protected void paintComponent(Graphics g) { super.paintComponent(g);
ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); sc.setBounds(0, 0, 200, 200); Composite content = new Composite(sc, SWT.NONE); content.setSize(300, 300); sc.setContent(content); Button button = new Button(content, SWT.PUSH); button.setText("Button"); button.setBounds(50, 50, 100, 50);
shell = new Shell(); shell.setSize(450, 300); shell.setText("SWT Application"); Button btnRadioButton = new Button(shell, SWT.RADIO); btnRadioButton.setBounds(0, 10, 90, 16); btnRadioButton.setText("Radio Button"); Button btnRadioButton_1 = new Button(shell, SWT.RADIO); btnRadioButton_1.setBounds(0, 30, 90, 16); btnRadioButton_1.setText("Radio Button"); Button btnRadioButton_2 = new Button(shell, SWT.RADIO); btnRadioButton_2.setBounds(0, 50, 90, 16); btnRadioButton_2.setText("Radio Button"); Composite composite = new Composite(shell, SWT.NULL); composite.setBounds(0, 70, 300, 200); composite.setLayout(new RowLayout()); Button btnRadioButton_3 = new Button(composite, SWT.RADIO); btnRadioButton_3.setBounds(0, 0, 90, 16); btnRadioButton_3.setText("Radio Button"); Button button = new Button(composite, SWT.RADIO); button.setText("Radio Button"); button.setBounds(0, 20, 90, 16); Button button_1 = new Button(composite, SWT.RADIO); button_1.setText("Radio Button"); button_1.setBounds(0, 40, 90, 16);
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10,10,300,300); Button b =new Button(shell, SWT.NONE); b.setText("Button"); b.setBounds(60,60,80,80); Button button = new Button(shell, SWT.PUSH); button.setText("NewButton"); button.setBounds(120,120,90,90); button.moveAbove(b); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
button.setBounds(-PADDING, -PADDING, CELL_SIZE + 2 * PADDING, CELL_SIZE + 2 * PADDING);
okButon.setBounds(30, 50, 100, dy);
Frame f=new Frame(); f.setLayout(null); Button b=new Button("Dummy"); //setBounds() methods accepts 4 // integer parameters /* 1. Location on x axis 2. Location on y axis 3. Width 4. Height */ b.setBounds(20,30,50,30); f.add(b);
public class MyClass { Label lblStatus; protected void createContents() { shell = new Shell(); shell.setSize(450, 300); shell.setText("SWT Application"); Button btnClickMe = new Button(shell, SWT.NONE); btnClickMe.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent arg0) { lblStatus.setText("Clicked"); // the compiler is aware of lblStatus } }); btnClickMe.setBounds(10, 10, 75, 25); btnClickMe.setText("Click Me"); lblStatus = new Label(shell, SWT.NONE); lblStatus.setBounds(10, 47, 75, 15); lblStatus.setText("Not clicked."); } }
@Override public void createPartControl(Composite parent) { parent.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); parent.setLayout(new FillLayout(SWT.HORIZONTAL)); ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); scrolledComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); scrolledComposite.setExpandHorizontal(true); scrolledComposite.setExpandVertical(true); scrolledComposite.setMinWidth(400); scrolledComposite.setMinHeight(400); Composite myViewParent = new Composite(scrolledComposite, SWT.NONE); myViewParent.setBackground(SWTResourceManager.getColor(SWT.COLOR_CYAN)); myViewParent.setLayout(null); Button btnNewButton = new Button(myViewParent, SWT.NONE); btnNewButton.setBounds(45, 237, 90, 30); btnNewButton.setText("New Button"); scrolledComposite.setContent(myViewParent); scrolledComposite.setMinSize(myViewParent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); parent.setSize(600, 300);
public static void main( String[] args ) { Listener listener = new Listener() { @Override public void handleEvent( Event event ) { System.out.println( event ); } }; Display display = new Display(); Shell shell = new Shell( display ); shell.setText( "Shell" ); shell.addListener( SWT.MouseDown, listener ); Button button = new Button( shell, SWT.PUSH ); button.setText( "Button" ); button.setBounds( 100, 100, 400, 100 ); button.addListener( SWT.MouseDown, listener ); shell.setSize( 600, 600 ); shell.open(); while( !shell.isDisposed() ) { if( !display.readAndDispatch() ) display.sleep(); } display.dispose(); }
objButton1.setBounds(40,35,50,50);
ans4YesBtn.setBounds(10, 20, 39, 16); ans4YesBtn.addSelectionListener(new SelectionAdapter() { @Override ans4NoBtn.setBounds(55, 20, 39, 16); ans4NoBtn.addSelectionListener(new SelectionAdapter() { @Override ans5NoBtn.setBounds(55, 21, 39, 16); ans5NoBtn.setText("No"); ans5YesBtn.setBounds(10, 21, 39, 16); ans5YesBtn.setText("Yes"); btnGainCalculation.setBounds(0, 236, 97, 25); btnGainCalculation.setText("Gain Calculation");
btnNext.setBounds(188, 55, 75, 25); btnNext.setText("Next");