Results 1 to 2 of 2
  1. #1
    qualitystreet is offline Member
    Join Date
    Apr 2011
    Posts
    4
    Rep Power
    0

    Default 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");

    }

    }

  2. #2
    qualitystreet is offline Member
    Join Date
    Apr 2011
    Posts
    4
    Rep Power
    0

    Default

    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

  1. custom tag library to populate a listbox
    By niteangell21 in forum New To Java
    Replies: 0
    Last Post: 11-29-2010, 08:37 PM
  2. Listbox from VB
    By Dipke in forum New To Java
    Replies: 2
    Last Post: 08-28-2010, 05:58 AM
  3. Remove an item from listbox
    By Dieter in forum Advanced Java
    Replies: 9
    Last Post: 09-21-2009, 10:40 PM
  4. [SOLVED] ArrayList to listbox
    By DanielS in forum AWT / Swing
    Replies: 12
    Last Post: 12-01-2008, 03:50 AM
  5. Listbox Add/Delete
    By Rageagainst20 in forum New To Java
    Replies: 2
    Last Post: 04-16-2008, 04:49 PM

Posting Permissions

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