Results 1 to 3 of 3
  1. #1
    ArneBassez is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default jList - add/remove items and query - using jFrame Form

    Hey,

    I have the following problem: I have made a GUI using a jFrame Form. Now I want to switch items between two list and I have found a tutorial to do so (The Guidebook - Swing Tutorials ). Only problem I have no idea how to do the following things in a jFrame form since the GUI items are fixed.

    1. Fill the jLists using a query. (querymethod will be declared in my database package)
    2. Switch items between list using 2 buttons ( jLists don't have parameter with defaultlist or something like that :p.)

    I will post my GUI form below (apparantly a lot more becomes visible if you CTRL+V your code): I have tried some things in jList>properties>model but withouth succes.. HELP!

    Thanks in advance:D


    import javax.swing.*;



    /**
    *
    * @author Arne
    */
    public class Beheren_BoekToevoegen extends javax.swing.JFrame {

    private static final Beheren_BoekToevoegen boektoevoegen = new Beheren_BoekToevoegen();
    static Beheren_BoekToevoegen getInstance()
    {
    return boektoevoegen;
    }

    /** Creates new form Beheren_BoekToevoegen */
    public Beheren_BoekToevoegen() {
    initComponents();
    }

    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    Titel = new javax.swing.JLabel();
    txtTitel = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    jList1 = new javax.swing.JList();
    btn_IN = new javax.swing.JButton();
    btn_OUT = new javax.swing.JButton();
    jScrollPane2 = new javax.swing.JScrollPane();
    jList2 = new javax.swing.JList();
    btnBoekToevoegen = new javax.swing.JButton();
    TXT_URL = new java.awt.TextField();
    btn_browse = new java.awt.Button();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosed(java.awt.event.WindowEvent evt) {
    formWindowClosed(evt);
    }
    public void windowClosing(java.awt.event.WindowEvent evt) {
    formWindowClosing(evt);
    }
    });

    Titel.setText("Geef een titel");

    jLabel1.setText("Selecteer een afbeelding als cover");

    jScrollPane1.setViewportView(jList1);

    btn_IN.setText(">>");
    btn_IN.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btn_INActionPerformed(evt);
    }
    });

    btn_OUT.setText("<<");
    btn_OUT.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btn_OUTActionPerformed(evt);
    }
    });

    jScrollPane2.setViewportView(jList2);

    btnBoekToevoegen.setText("Toevoegen");

    TXT_URL.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    TXT_URLActionPerformed(evt);
    }
    });

    btn_browse.setActionCommand("button1");
    btn_browse.setLabel("Browse...");
    btn_browse.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btn_browseActionPerformed(evt);
    }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(29, 29, 29)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
    .addComponent(jLabel1)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(Titel)
    .addGap(10, 10, 10)))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
    .addGroup(layout.createSequentialGroup()
    .addComponent(TXT_URL, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(btn_browse, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addComponent(txtTitel, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addGroup(layout.createSequentialGroup()
    .addGap(124, 124, 124)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(26, 26, 26)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(btn_IN, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(btn_OUT, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(26, 26, 26)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))))
    .addGroup(layout.createSequentialGroup()
    .addGap(330, 330, 330)
    .addComponent(btnBoekToevoegen)))
    .addContainerGap(51, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
    .addGap(49, 49, 49)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(txtTitel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(Titel))
    .addGap(14, 14, 14)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
    .addComponent(jLabel1)
    .addComponent(TXT_URL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(btn_browse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 20, Short.MAX_VALUE)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGroup(javax.swing.GroupLayout.Alignment.LEADIN G, layout.createSequentialGroup()
    .addGap(25, 25, 25)
    .addComponent(btn_IN)
    .addGap(18, 18, 18)
    .addComponent(btn_OUT)))
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(10, 10, 10)
    .addComponent(btnBoekToevoegen)
    .addGap(20, 20, 20))
    );

    pack();
    }// </editor-fold>

    private void btn_INActionPerformed(java.awt.event.ActionEvent evt) {

    }

    private void formWindowClosed(java.awt.event.WindowEvent evt) {

    }

    private void formWindowClosing(java.awt.event.WindowEvent evt) {
    this.setDefaultCloseOperation ( JFrame.DISPOSE_ON_CLOSE );
    }

    private void btn_browseActionPerformed(java.awt.event.ActionEve nt evt) {
    Browse browse = Browse.getInstance();
    browse.setLocationRelativeTo(this);
    browse.show();
    }

    private void TXT_URLActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void btn_OUTActionPerformed(java.awt.event.ActionEvent evt) {

    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new Beheren_BoekToevoegen().setVisible(true);
    }
    });
    }

    // Variables declaration - do not modify
    private java.awt.TextField TXT_URL;
    private javax.swing.JLabel Titel;
    private javax.swing.JButton btnBoekToevoegen;
    private javax.swing.JButton btn_IN;
    private javax.swing.JButton btn_OUT;
    private java.awt.Button btn_browse;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JList jList1;
    private javax.swing.JList jList2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField txtTitel;
    // End of variables declaration


    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    1. Use code tags, nobody's going to look at unformatted code.
    2. Get rid of the NetBeans/Matisse autogenerated code, it's ugly and detracts from the problem. Honestly, how hard is it to hand code a GUI that demonstrates two lists and the problems you're having with them?

    db

  3. #3
    ArneBassez is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    Roger that!

    anyway, just solved the problem using:

    DefaultListModel lijst1 = new DefaultListModel();
    jList1.setModel(lijst1);

    GUI builders are strange things:)

Similar Threads

  1. Adding \ removing items from Jlist
    By Desperado in forum AWT / Swing
    Replies: 10
    Last Post: 12-17-2009, 01:48 PM
  2. How can I save items in my JList?
    By yoodidoo in forum New To Java
    Replies: 2
    Last Post: 08-02-2009, 07:36 AM
  3. jlist items
    By bullstreetboy in forum New To Java
    Replies: 6
    Last Post: 04-12-2009, 06:30 PM
  4. CheckBox Jlist items
    By dropez in forum AWT / Swing
    Replies: 1
    Last Post: 03-26-2009, 08:39 PM
  5. How to remove selected items in a SWT table
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:29 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
  •