Results 1 to 2 of 2
Thread: Problem with Listbox
- 04-01-2011, 09:01 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 4
- Rep Power
- 0
Problem with Listbox
Hi,
I have a gui window that I want to be able to load items into a Listbox from a CSV file.
If I create another class to read the text file and load it into an array, how can I them add the items to the ListBox on the form?
Do I need some sort of Listner?
Thanks
import org.eclipse.swt.widgets.Display;
public class guiwindow {
protected Shell shell;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
guiwindow window = new guiwindow();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
List lstItems = new List(shell, SWT.BORDER);
lstItems.setBounds(10, 10, 197, 242);
Button btnLoadFile = new Button(shell, SWT.NONE);
btnLoadFile.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
//run import from csv here
}
});
btnLoadFile.setBounds(220, 10, 75, 25);
btnLoadFile.setText("Load File");
}
}
- 04-05-2011, 08:25 AM #2
Member
- Join Date
- Apr 2011
- Posts
- 4
- Rep Power
- 0
To fix it I had to declare my listbox as a public in the class,
public class guiwindow {
protected Shell shell;
public List lstItems;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
guiwindow window = new guiwindow();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
lstItems = new List(shell, SWT.BORDER);
lstItems.setBounds(10, 10, 197, 242);
Button btnLoadFile = new Button(shell, SWT.NONE);
btnLoadFile.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
//run import from csv here
}
});
btnLoadFile.setBounds(220, 10, 75, 25);
btnLoadFile.setText("Load File");
}
}
Similar Threads
-
custom tag library to populate a listbox
By niteangell21 in forum New To JavaReplies: 0Last Post: 11-29-2010, 08:37 PM -
Listbox from VB
By Dipke in forum New To JavaReplies: 2Last Post: 08-28-2010, 05:58 AM -
Remove an item from listbox
By Dieter in forum Advanced JavaReplies: 9Last Post: 09-21-2009, 10:40 PM -
[SOLVED] ArrayList to listbox
By DanielS in forum AWT / SwingReplies: 12Last Post: 12-01-2008, 03:50 AM -
Listbox Add/Delete
By Rageagainst20 in forum New To JavaReplies: 2Last Post: 04-16-2008, 04:49 PM


LinkBack URL
About LinkBacks

Bookmarks