Change image with JList


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Change image with JList

Threaded View

  1. #1
    Join Date
    Sep 2004
    Posts
    59

    Change image with JList

    Im not good with java and it seems that i cant this working so i give this a try..

    What i want is to be able to change image when clicked on the JList i treit it with setIcon() but it didnt work

    The

    this is the code:

    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;

    public class CardList extends JFrame
    implements ListSelectionListener {

    public JLabel l = new JLabel();
    public String[] creature = {"AnabaShaman", "BalduvianBarbarians",};


    ////
    //private image[] col = {code here to change image?};
    ////



    public JList list = new JList(creature);
    public JScrollPane sp = new JScrollPane(list);
    public JLabel image2 = new JLabel(new ImageIcon("c:\\image.jpg"));

    public CardList() {
    Container c = getContentPane();
    c.setLayout (new FlowLayout());
    c.add(sp);
    c.add(l);
    c.add(image2);
    l.setForeground(Color.blue);
    l.setText("Show card");
    l.setPreferredSize(new Dimension(100,75));
    list.setVisibleRowCount(3);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addListSelectionListener(this);
    pack();
    setSize(300,420);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }


    public void valueChanged(ListSelectionEvent e) {
    // l.setForeground(col[list.getSelectedIndex()]);
    }

    public static void main (String[] arg) {
    CardList CL = new CardList ();
    }
    }



    example:

    http://arkserver.servehttp.com/stuff/dev/mtgdev1.jpg
    Last edited by Arkie_student; 05-12-2005 at 11:46 AM.
    My own java video tutorials, feel free to watch it.
    http://www.engineeringserver.com/for...amming-b311.0/ Need java help? For beginning and intermediate java coders!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center