Array of SWT Buttons [message #909245] |
Thu, 06 September 2012 15:59  |
Eclipse User |
|
|
|
In the code below I try to create an array of Buttons but I get a NullPointerException error when I try to do anything with them. Can anyone help?
package buttonArray;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
public class ButtonArray {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Try Button Array");
// creates the gridlayout
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
shell.setLayout(gridLayout);
// creates the buttons
Button[] button = new Button[3];
// line below causes :
// Exception in thread "main" java.lang.NullPointerException
// at buttonArray.ButtonArray.main(ButtonArray.java:28)
button[0].setParent(shell);
shell.pack();
shell.open();
shell.setSize(700, 700);
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.10693 seconds