Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,250 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,223 people online right now. Registration is fast and FREE... Join Now!




jList and vector

 
Reply to this topicStart new topic

jList and vector

abgorn
25 Aug, 2008 - 11:33 AM
Post #1

Hello Crap for Brains
Group Icon

Joined: 5 Jun, 2008
Posts: 880



Thanked: 5 times
Dream Kudos: 50
My Contributions
I'm trying to use a vector in a jList but I don't know how and I was wondering if anyone could help. This is the code for my project(made in NetBeans 6.1):
CODE

package texteditor;

import javax.swing.*;


public class ReadFileUI extends javax.swing.JDialog {
    
    public ReadFileUI(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    

    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        OpenList = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Open File...");

        OpenList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        OpenList.setToolTipText("Select File to Open");
        jScrollPane1.setViewportView(OpenList);

        jButton1.setText("Open...");

        jButton2.setText("Cancel");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }
    

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ReadFileUI dialog = new ReadFileUI(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    public static javax.swing.JList OpenList;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JScrollPane jScrollPane1;
    
}

User is offlineProfile CardPM
+Quote Post

pbl
RE: JList And Vector
25 Aug, 2008 - 01:38 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
Create your Vector first
then create your JList from that vector
OpenList = new JList(vector);

and whatever you add/remove from the Vector will be displayed by yhe JList after a repaint()
User is offlineProfile CardPM
+Quote Post

abgorn
RE: JList And Vector
26 Aug, 2008 - 03:09 AM
Post #3

Hello Crap for Brains
Group Icon

Joined: 5 Jun, 2008
Posts: 880



Thanked: 5 times
Dream Kudos: 50
My Contributions
QUOTE(pbl @ 25 Aug, 2008 - 02:38 PM) *

Create your Vector first
then create your JList from that vector
OpenList = new JList(vector);

and whatever you add/remove from the Vector will be displayed by yhe JList after a repaint()

Thank you very much! icon_up.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:11AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month