Results 1 to 4 of 4
  1. #1
    varesa is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Question How to change controls attributes

    Im trying to make, that pressing a button changes the other one. I have tried to refer the button in many ways, but it seems to always give NullPointerException.

    My code: https://github.com/varesa/Manage_ser...y/esav/Manager

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Most members here won't follow an external link, and many of those sites are blocked for members who are behind a corporate firewall. To get better help sooner, post a SSCCE that clearly demonstrates your problem.

    db

  3. #3
    varesa is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default Some code

    For clearness, I tried to recreate some code that resembles my programs structure:

    Java Code:
    import org.eclipse.swt.widgets.Display;
    
    public class Test {
    	private Button btn2;
    
    	public static void main(String[] args) {
    		try {
    			Test window = new Test();
    			window.open();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public void open() {
    		Display display = Display.getDefault();
    		Shell shell = new Shell();
    		shell.setSize(204, 177);
    		shell.setText("SWT Application");
    		shell.setLayout(new FillLayout(SWT.HORIZONTAL));
    		
    		Button btn1 = new Button(shell, SWT.NONE);
    
    		btn1.setText("New Button");
    		
    		btn2 = new Button(shell, SWT.NONE);
    		btn2.setText("New Button");
    		
    		btn1.addSelectionListener(new SelectionAdapter() {
    			@Override
    			public void widgetSelected(SelectionEvent e) {
    				someotherclass.method();
    			}
    		});
    
    		shell.open();
    		shell.layout();
    		while (!shell.isDisposed()) {
    			if (!display.readAndDispatch()) {
    				display.sleep();
    			}
    		}
    	}
    	
    	public void someMethod() {
    		getBtn2().setText("xxx");
    	}
    
    	public Button getBtn2() {
    		return btn2;
    	}
    }
    
    class someotherclass {
    	
    	public static void method() {
    		Test t = new Test();
    		t.someMethod();
    	}
    	
    }

  4. #4
    varesa is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Question Help?

    Any help? Id like to get over this error as soon as possible

Similar Threads

  1. Replies: 9
    Last Post: 01-20-2011, 04:01 PM
  2. how to change controls border color
    By altu57 in forum AWT / Swing
    Replies: 1
    Last Post: 07-10-2010, 04:11 AM
  3. Controls
    By zzpprk in forum AWT / Swing
    Replies: 2
    Last Post: 11-04-2009, 02:32 AM
  4. how to place the controls >
    By makpandian in forum AWT / Swing
    Replies: 1
    Last Post: 12-18-2008, 06:17 AM
  5. Controls in Eclipse
    By hisouka in forum Eclipse
    Replies: 6
    Last Post: 08-04-2008, 11:27 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •