Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: jList and other question

  1. #1
    Bulgarian is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default jList and other question

    Hello! I use swing-components and create List, Button and Textbox. How to add item in List, which is text in Textbox after clicking the button?

    I use this:
    Java Code:
    public DefaultListModel dlm=new DefaultListModel();
    //add dlm in jList generate source: jList1 = new javax.swing.JList(dlm);
    
    //and create:  private final void addList(){
                          dlm.addElement(jTextField1.getText()); }
     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            addList();
    }
    But text, that I write can't put in the List.

    I try this:
    Java Code:
      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            final String old = null;
            final String s=jTextField1.getText();
            jList1.setModel(new javax.swing.AbstractListModel() {
            String strings=s;
    
            public int getSize() { return i; }
            public Object getElementAt(int i) { return strings; }
            });
        }
    Add first item - OK, but when I write second first change too and have two same items.
    Any help?

    My second question is how to change buttons performance in swing component File Chooser or is any other chance when press button to open a file from my system?
    Thank you!
    Last edited by sunde887; 08-07-2011 at 03:43 PM. Reason: Switched quote tags to code tags, [code]...[/code]

  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

    Read the API for JList and follow the link to the tutorial on How to Use Lists where you will find a section on Adding Items to and Removing Items from a List.

    Your second question is not clear at all. A JFileChooser is for choosing/selecting a file, not for opening it.

    Further, I would advise you to stay away from the NetBeans visual designer -- it's not a beginners' tool and is much more difficult to learn than simple swing coding. And to get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem. Next time, don't forget to use the code tags correctly.

    db
    Fubarable likes this.

  3. #3
    Bulgarian is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default

    Thank you! I want to say, that I want to select file from my system, put in the JList and use it, specifically .mp3 files. But I can't find information how to work with .mp3-files in my projects...

  4. #4
    Bulgarian is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default

    I fixed FileChooser, but Is any Filter in Netbeans for audio files (for image files is ImageFilter) ?

  5. #5
    Bulgarian is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default

    How to import and play audio file in my program?

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

    Default

    Quote Originally Posted by Bulgarian View Post
    I fixed FileChooser, but Is any Filter in Netbeans for audio files (for image files is ImageFilter) ?
    Open wide.

    Read the API for JFileChooser and follow the link to the tutorial on How to Use File Choosers where you will find a section on Filtering the List of Files

    To get better help sooner, post a SSCCE that clearly demonstrates your problem.

    db

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

    Default

    Quote Originally Posted by Bulgarian View Post
    How to import and play audio file in my program?
    Go through the static methods of the Applet class. Find the method you need and look up the API for the class of its return value.

    db

    edit In future, please start a new thread for any unrelated question.
    Last edited by DarrylBurke; 08-10-2011 at 08:22 AM.

  8. #8
    Bulgarian is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default

    I done Audio-filter. If any interesting, this is the code:
    Java Code:
    final JFileChooser fc=new JFileChooser();
     FileNameExtensionFilter fnef=new FileNameExtensionFilter("Music files", "mp3", "wav", "m3u", "pls", "asx");
     fc.setAcceptAllFileFilterUsed(false); 
     fc.setFileFilter(fnef);
    But I can't undarstand you about audio files. Can't find anything in internet, too. Can you tell me more?

Similar Threads

  1. Link one JList to another JList
    By mib1bee in forum AWT / Swing
    Replies: 1
    Last Post: 12-31-2010, 08:10 PM
  2. Link one JList to another JList
    By mib1bee in forum Advanced Java
    Replies: 1
    Last Post: 12-30-2010, 07:35 PM
  3. Link one JList to another JList
    By mib1bee in forum New To Java
    Replies: 1
    Last Post: 12-30-2010, 07:24 PM
  4. Java JList Alignment Question?
    By antitru5t in forum New To Java
    Replies: 1
    Last Post: 03-10-2009, 07:44 PM
  5. Help with JList
    By Albert in forum NetBeans
    Replies: 1
    Last Post: 07-13-2007, 04:42 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
  •