JList problem

Hi ,
Iam having a JList with some strings in it .I'll be selecting multiple values from it .(Multiple_interval_selection model) .I need to store the values in JList to database (Ms access).I couldn't do it .So many times i have tried .The values are getting again and again if i concatenate the old values with the new one .Also if it possible to retrieve the values from database after storing it .Please help me out.

By posting in the right forum.LOL

Similar Messages

  • JList problem "again??"

    hi i dont mean to double post but i dont think i pasted in enought code before when i posted this problem, so here is some more if anyone can
    help me out i send them 5 more of the little guys
    thanks againhello
    privious post!!
    "i want to get the selected value/values from a Jlist and put them into a SQL query i think i should have each selected value as a string so i can concatinate them into the query but i cant seem to be able to do this does any one know how can acheive this??"
    code:
    JInternalFrame frame3 = new JInternalFrame("User Adminstration info",true,true,true,true);
    Container content = frame3.getContentPane();
    JLabel l1=new JLabel("Username");
    JLabel l2=new JLabel("Hostname");
    JLabel l3=new JLabel("Password");
    JTextField t1=new JTextField(11);
    JTextField t2=new JTextField(11);
    JPasswordField pass1=new JPasswordField(11);
    JPanel p1=new JPanel();
    String all = "ALL Privileges";
    JList privilegesList;
    String privilegetype[]={"SELECT","INSERT","UPDATE","DELETE","CREATE","DROP"};
    JList databaseList;
    String databasename[] = {"db1","db2","db4","db5",};
         JPanel p2=new JPanel();
         JPanel p3=new JPanel();
    JButton b1=new JButton("Submit Details");
         JPanel p4=new JPanel();
         JPanel p5=new JPanel();
         JPanel p6=new JPanel();
    frame3.setVisible(true);
         content= frame3.getContentPane();
         content.setLayout(new BorderLayout());
         p1.setLayout(new GridLayout(3,2));
         privilegesList = new JList( privilegetype );
                                  privilegesList.setVisibleRowCount( 5 );
                                  privilegesList.setFixedCellHeight( 15 );
                                  privilegesList.setFixedCellWidth( 150 );
                                  privilegesList.setSelectionMode(
                                  ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
         databaseList = new JList( databasename);
                                  databaseList.setVisibleRowCount( 5 );
                                  databaseList.setFixedCellHeight( 15 );
                                  databaseList.setFixedCellWidth( 150 );
                                  databaseList.setSelectionMode(
                                  ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
    p1.add(l1);p1.add(t1);
    p1.add(l2);p1.add(t2);
    p1.add(l3);p1.add(pass1);
    p1.setBorder(new TitledBorder(new EtchedBorder(),"User Details "));
    //p2.setLayout(new GridLayout(8,0));
         p2.add(privilegesList);
         p2.setBorder(new TitledBorder(new EtchedBorder(),"Privileges"));
         //p3.setLayout(new GridLayout(5,0));
         p3.add(databaseList);
         p3.setBorder(new TitledBorder(new EtchedBorder(),"DataBases"));
         p4.setLayout(new GridLayout(0,2));
         p4.add(p2);
    p4.add(p3);
         p6.add(b1);
         content.add(p1,BorderLayout.NORTH);
         content.add(p4,BorderLayout.CENTER);
                             content.add(p6,BorderLayout.SOUTH);
                   p5.setBorder(new TitledBorder(new EtchedBorder(),"User Adimnstration"));
                   frame3.setSize(500,430);
                   thedesktop.add( frame3);
                   setVisible(true);

    I suggest you read this section from the Swing tutorial on "How to Use Lists" for sample code and explanations:
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

  • Adding JScrollPane to a JList problems

    Hi,
    I am having problem in trying to add a JScrollPane to a JList, it doesnt appear i don't understand what i am doing wrong.
    private String [] mainMenu = {"Phonebook", "Messages", "User Options", "Phone Status"};
    private JList main = new JList(mainMenu);
    private JScrollPane scrolling = new JScrollPane(main);
    public Mobile()
             main.setLocation(60, 110);
             main.setSize(90, 50);
             add(scrolling);
             scrolling.setVisible(true);
    }

    The code to run the app is:
    import java.awt.*;
    import javax.swing.*;
    class MobileGUI {
         public static void main(String[] args) {
              JFrame frame = new JFrame("Mobile Phone Simulation");
              Container pane = frame.getContentPane();
              pane.add(new Mobile());
              frame.setSize(340, 625);
              frame.show();
    }The class that contains the components is:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    class Mobile extends JComponent {
    private String[] mainMenu = {"Phonebook", "Messages", "User Options", "Phone Status"};
    private JList main = new JList(mainMenu);
    private JScrollPane scrolling = new JScrollPane(main);
    public JTextArea display = new JTextArea(6, 30);
    public MobileGUI()
              //Displays
              setLayout(null);
              //Display for messages
              display.setLocation(120, 60);
              display.setSize(90, 50);
              add(display);
              display.setVisible(false);
              //MainMenu Jlist Display
              main.setLocation(120, 60);
              main.setSize(90, 50);
              add(scrolling);
              scrolling.setVisible(true);
         public void paint(Graphics g) {
         g.setColor(Color.gray.brighter());
         g.fillRoundRect(30, 30, 270, 530, 40, 20);
         g.setColor(Color.black);
         g.fillArc(30, 30, 270, 320, 0, 180);
        g.fillArc(30, -180, 270, 740, 180, 180);
         g.setColor(Color.gray);     
         super.paint(g);       
    }The JList does not appear neither does the JScrollPane

  • JList problems, can't write to a list

    Hi there....can anyone help???
    I'm having a problem with a dialog box...I use a dialog box to logon a new user (client) to my server, but the GUI on the client's side isn't showing who's online so to speak(I'm using a JList as my 'buddy' list type of window)....How do I get the dialog box to send the user's name to my client's GUI and add it to my who's online box??? Conversely how do I get the name to be removed when the user disconnects from the server??? Thanks everyone for any help you can provide....

    You need to refresh the JList every time the data changes:
    JList myjlist = new JList();
    Vector data = new Vector(); //or use an array of type Object
    //data changes
    myjlist.setListData(data);

  • Jlist problems

    I am having problems with Jlist such that it returns index selectedIndex values in the valueChanged method from its interface method.
    SwingUtilities.invokeLater(
    new Runnable()
    public void run()
    coLogger.debug("csLocationName = " + csLocationName);
    csLocationName = SVOpSParseKanji.convertDelimToKanji(csLocationName) ;
    coLocationTxtFld.setText(csLocationName);
    coListModel.setValues(coWrapperFacilityList);
    coList.clearSelection();
    populateGeneralFacilityTypeList(coFacilityTypeLists);
    if(coTempFacility.getFcltDataInfo().getFcltCode().length() > 0)
    int iIndex = coListModel.getIndexed(coFacility);
    coList.setSelectedIndex(iIndex);
    coList.ensureIndexIsVisible(iIndex);
    coGlassPane.setVisible(false);
    after setting this the valueChanged method returns
    a selectedIndex value of 5 and 10
    what seems to be the problem?.. thanks

    a selectedIndex value of 5 and 10if the problem is you are getting 2 values, itemStateChanged() fires twice,
    once for DESELECTED, again for SELECTED
    you separate the two by checking getStateChange()

  • Help needed, stuck in a DnD JList problem

    Hi guys
    I got this code from internet and I was really expecting it would work, but it is not really transferring my Object to the other JList.
    I someone can help me I would appreciate that very much, below is the code, to the Model and to the Transfer.
    Model
    public class TabVernizListModel extends AbstractListModel {
        ArrayList<TabelaVerniz> lista;
        public TabVernizListModel(ArrayList<TabelaVerniz> lista) {
            this.lista = lista;
        public TabVernizListModel() {
            lista = new ArrayList<TabelaVerniz>();
        public Object getElementAt(int index) {
            Object item = null;
            if (lista != null) {
                item = lista.get(index);
            return item;
        public Integer getSelectedIndex(TabelaVerniz item) {
            int index = lista.indexOf(item);
            return index;
        public int getSize() {
            int size = 0;
            if (lista != null) {
                size = lista.size();
            return size;
        public void remove(int index) {
            fireIntervalRemoved(this, index, index);
            lista.remove(index);
        // This is not really working, does not update the 2nd List
        public void add(TabelaVerniz tabela) {
            if (lista == null) {
                lista = new ArrayList<TabelaVerniz>();
            lista.add(tabela);
            int index = this.getSelectedIndex(tabela);
            super.fireIntervalAdded(this, lista.size() - 1, lista.size() - 1);
    The Transfer:
    public class TabVernizTransferHandler extends TransferHandler {
        JList listaEsquerda;
        JList listaDireita;
        // This transfer handler needs to know about the two JLists !
        public TabVernizTransferHandler(JList leftList, JList rightList) {
            super();
            listaEsquerda = leftList;
            listaDireita = rightList;
        @Override
        public boolean importData(JComponent component, Transferable trasferedObject) {
            JList lista = (JList) component;
            try {
                int sourceIndex = Integer.parseInt((String) trasferedObject.getTransferData(DataFlavor.stringFlavor));
                // figure out which is the source and which is the dest.
                TabVernizListModel source;
                TabVernizListModel dest;
                if (lista == listaEsquerda) {
                    source = (TabVernizListModel) listaDireita.getModel();
                    dest = (TabVernizListModel) listaEsquerda.getModel();
                } else {
                    source = (TabVernizListModel) listaEsquerda.getModel();
                    dest = (TabVernizListModel) listaDireita.getModel();
                // get the source object
                TabelaVerniz tabela = (TabelaVerniz) source.getElementAt(sourceIndex);
                // add it to the other model.
                dest.add(tabela);
                // and remove from the source
                source.remove(sourceIndex);
            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.println("Import failed!");
                return (false);
            return (true);
        @Override
        protected Transferable createTransferable(JComponent c) {
            JList jl = (JList) c;
            // we want the currently selected index
            Integer index = new Integer(jl.getSelectedIndex());
            // and we transfer it as a string
            Transferable t = new StringSelection(index.toString());
            return t;
        @Override
        public int getSourceActions(JComponent c) {
            return MOVE;
        @Override
        public boolean canImport(JComponent c, DataFlavor[] flavors) {
            for (int i = 0; i < flavors.length; i++) {
                if (flavors.getHumanPresentableName().equals("Unicode String")) {
    return (true);
    return (false);
    }Can anyone point what is wrong here?
    When I drag from the left list to the right list it just don't drop.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    The Swing tutorial on Drag and Drop has a working example with a JList.

  • JList Problem (please help)

    Hi,
    I ve a panel on my main screen.JList and ComboBox are on it.Their Items are derrived from the database and put it ina Vector .By using that vector I filled those objects.In another popupframet that is also releated to main Frame, I can update Database.But altough I ve tried many validate repaint and updateUI methods I cannot repaint the panel.I can see that the Jlist has the new data but I cannot display it.Do you have any Idea about it.
    I'd be glad if you can help me.

    You need to recreate the model using the Vector. Then use:
    list.setModel(...);

  • JList problems: howto use my own indexes taken from database.

    Hello, I'm new to Java.
    I'm reading names and Unique ID from my employee table. but when selected from listbox I want to get ID of my employee not SelectedIndex of jList is there any ready solution or what can you advice.
    Example:
    ID NAME
    1 Fayziddin Jurayev
    2 Sanjar Sharipov.
    48 Muhammad Jurayev
    49 -----XXXXX================> This record has been deleted
    50 Sanjar Sharipov
    As you see here two person have the same name also looking for person in the table using name will cause mistakes. But if I use SelectedIndex of person in a listbox again I make mistake as 49 th record is deleted.
    I think best solution is to store at the array somewhere NAMES and ID's and use ID to recognize correctly selected person.
    Can someone advice the easiest way to do it(I've used Visual Fox Pro before JAVA)
    Thanks

    Check out this posting:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=608684

  • JList: doubleClick selection

    Hey,
    i want an item of JList to be selected by doubleClick. i know how to add a doubleClick mouselistener to JList (http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JList.html) and
    how to get all registered mouselisteners of JList.
    problem: how can i remove just the singleClick-Mouselistener of JList.
    list.removeMouseListener(???);thank you very much for your help,
    BJoa

    And how did you solve it, just in case somebody has the same question and actually uses the search?

  • Object serialisation & GUI

    Howdy to all,
    Not too sure if this is a Swing or an I/O serialisation issue. So I'll take my chances and post here.
    I have 3 classes:
    1) PostcodeStream - essentially writes and reads a PostcodePanel object.
    2) PostcodePanel - sets up a list (JList) of cities and postcodes.
    3) PostcodePanelTest - the application.
    This application should allow you to select a city from a JList and it then displays the corresponding postcode in a JLabel (I know really exciting stuff ;-) ). I'm more interested in the object serialisation aspects of the application. The GUI has two buttons in the bottom panel - Save and Restore. The Save button writes the postcode panel object to file and the restore button restores the object back to the GUI.
    Everything works fine (that is - I can save the object and then successfully restore it), except for the fact that when I click Save, the JList disappears altogether and just leaves the postcode label. What I expect is that the Jlist should not be removed from the GUI when the save button is clicked - but for some reason it does.
    If you refer to the actionPerformed() method in class PostcodePanelTest for the btnSave JButton, all I do is call a method that writes the object to file. For the life of me I can't figure out why the JList "vanishes" from the GUI.
    Here's the code for all three classes - the listings aren't too long I hope. I'd appreciate any feedback as to why I'm observing this behaviour for the save action. And again I apologise if this is not the right forum for my query.
    Class - PostcodeStream.java
    ===========================
    import java.io.*;
    import java.io.Serializable;
    import java.util.*;
    import javax.swing.*;
    public class PostcodeStream implements Serializable {
         private Date dateSaved;
         public PostcodeStream() {
         public void writePostcode(JPanel pnlPostcode) { // Write a PostcodePanel object
              try {
                   FileOutputStream fos = new FileOutputStream("Postcode.dat");
                   ObjectOutputStream out = new ObjectOutputStream(fos);
                   out.writeObject(pnlPostcode);
                   out.writeObject(new Date());
                   out.close();
              catch (IOException ex) {
                   System.out.println(ex);
         public PostcodePanel readPostcode() {          // Read a PostcodePanel object
              PostcodePanel pnlPostcode = null;
              try {
                   FileInputStream fis = new FileInputStream("Postcode.dat");
                   ObjectInputStream in = new ObjectInputStream(fis);
                   pnlPostcode = (PostcodePanel)in.readObject();     // Read the panel
                   dateSaved = (Date)in.readObject();          // Date the panel saved
                   in.close();
              catch (IOException exIO) {
                   System.out.println(exIO);
              catch (ClassNotFoundException exClass) {  // Thrown by readObject()
                   System.out.println(exClass);
              return pnlPostcode;
         public String getSavedDate() {     // Return the date & time the panel was saved
              return dateSaved.toString();
    } PostcodePanel.java
    ==================
    import java.awt.*;
    import javax.swing.*;
    public class PostcodePanel extends JPanel {
         protected JList lstCities;
         protected JLabel lblPostcode;
         private String[] cities = {"Sydney", "Gosford", "Woy Woy", "Canberra", "Melbourne",
                        "Brisbane", "Adelaide", "Perth", "Hobart"};
         private String[] postcodes = {"2000", "2500", "2257", "2600", "3000",
              "4000", "5000", "6000", "7000"};
         public PostcodePanel() {
              lstCities = new JList(cities);
              lblPostcode = new JLabel(postcodes[0]);
              this.add(new JScrollPane(lstCities));
              this.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
              this.add(lblPostcode);
              lstCities.setSelectedIndex(0);          // Set default to Sydney
              lstCities.setVisibleRowCount(4);
              this.setBorder(BorderFactory.createEtchedBorder());
         public void setPostcode() {
              int index = lstCities.getSelectedIndex();
              lblPostcode.setText(postcodes[index]);
    PostcodePanelTest.java
    ======================
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class PostcodePanelTest extends JFrame implements ActionListener, ListSelectionListener {
         private JButton btnRestore = new JButton("Restore List");
         private JButton btnSave = new JButton("Save List");
         private JLabel lblStatus = new JLabel();
         private JPanel pnlCentre = new JPanel();
         private PostcodePanel pnlPostcode = new PostcodePanel();
         private PostcodeStream postcodeStream = new PostcodeStream();
         public PostcodePanelTest() {
              pnlCentre.add(pnlPostcode);
              JPanel pnlSouth = new JPanel();
              pnlSouth.add(btnSave);
              pnlSouth.add(btnRestore);
              Container cn = this.getContentPane();     
              cn.setLayout(new BorderLayout(10, 10));
              cn.add(lblStatus, BorderLayout.NORTH);
              cn.add(pnlCentre, BorderLayout.CENTER);
              cn.add(pnlSouth, BorderLayout.SOUTH);
              btnSave.addActionListener(this);
              btnRestore.addActionListener(this);
              pnlPostcode.lstCities.addListSelectionListener(this);
         public void valueChanged(ListSelectionEvent e)  {
              if (e.getSource() == pnlPostcode.lstCities) {
                   pnlPostcode.setPostcode();
         public void actionPerformed(ActionEvent e) {
              if (e.getSource() == btnSave) {
                   postcodeStream.writePostcode(pnlPostcode);
              else if (e.getSource() == btnRestore) {
                   // Read the saved panel & remove the old one
                   PostcodePanel p = postcodeStream.readPostcode();
                   pnlCentre.remove(pnlPostcode);
                   pnlPostcode = p;
                   pnlCentre.add(pnlPostcode, BorderLayout.CENTER);
                   // Set the status label with date/time of saving object
                   lblStatus.setText("Panel saved at:" + postcodeStream.getSavedDate());
                   pnlCentre.repaint();
         public static void main(String args[]) {
              PostcodePanelTest app = new PostcodePanelTest();
              app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
              app.setTitle("Read and write a Postcode panel");
              app.setSize(300, 200);
              app.setVisible(true);
    } Thankyou and regards,

    Good day to all,
    I have an update on my problem.
    The API documentation for JPanel (or any Swing component for that matter) contains the following paragraph:
    Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.
    Without really understanding what "short term storage" really meant, I changed my PostcodeStream class to now use the XMLEncoder and XMLDecoder classes in place of the ObjectOutputStream and ObjectInputStream classes respectively. The code for this class now looks like so:
    import java.io.*;
    import java.util.*;
    import java.beans.*;
    public class PostcodeStream {
        private Date dateSaved;
        public PostcodeStream() {
        public void writePostcode(PostcodePanel pnlPostcode) {
            try {
                XMLEncoder out = new XMLEncoder(
                                  new BufferedOutputStream(
                                   new FileOutputStream("test.xml")));
                out.writeObject(new Date());
                out.writeObject(pnlPostcode);
             out.close();
            catch (IOException ex) {
             System.out.println(ex);
        public PostcodePanel readPostcode() {
            PostcodePanel pnlPostcode = null;
         try {
                XMLDecoder in = new XMLDecoder(
                                 new BufferedInputStream(
                                  new FileInputStream("test.xml")));
                dateSaved  = (Date)in.readObject();
             pnlPostcode = (PostcodePanel)in.readObject();
             in.close();
         catch (IOException exIO) {
             System.out.println(exIO);
            return pnlPostcode;
        public String getSavedDate() {
            return dateSaved.toString();
    }Now the good news is that the "disappearing JList" problem is resolved - it no longer vanishes when you save. However, the JList does not restore correctly, it always defaults to the first item in the list regardless of what it was when Save List was clicked. On checking the test.xml file that is used to store the objects, no details about the JPanel object are stored. The file contents are:
    <?xml version="1.0" encoding="UTF-8"?>
    <java version="1.5.0" class="java.beans.XMLDecoder">
    <object class="java.util.Date">
    <long>1122570765453</long>
    </object>
    <object class="PostcodePanel"/>
    </java>
    So it looks as though the use of the XMLEncoder and XMLDecoder classes has resolved the disappearing list issue - but now it doesn't restore the list correctly. The date object seems to be stored correctly but not the JPanel object. Well, that's my update on this problem. Any suggestions on how to correct this are truly appreciated.
    Cheers,

  • Accesing object instances

    how do I acces an object at runtime? My problem is that I have an empty JList I want to fill up with the information inside another object called SPList. The problem is that I need to access that instance of the SPList class. Also how can I create static classes?

    how do I acces an object at runtime? My problem is
    that I have an empty JList I want to fill up with the
    information inside another object called SPList. TheAdd a property change listener to the list. Use the property change event to send the list to the JList.
    problem is that I need to access that instance of the
    SPList class. Also how can I create static classes?static classes? Why do you need them?
    public
    class SingleClass
      // Just an single class
    public
    class SingleClassWithOneStaticMember
      // Non static class
      class NonStaticMember
        // a non-static member only exists if the enclosing class exists
        // instantiation is only possible if you have an object of the
        // enclosing class
        // SingleClassWithOneStaticMember object
        //   = new SingleClassWithOneStaticMember();
        // SingleClassWithOneStaticMember.NonStaticMember member
        //   = object.new NonStaticMember();
      static
      class StaticMember
        // this class always exists, if the enclosing class
        // exists, but is only reachable from within the package
        // use this to model data, that is tied to the enclosing
        // class, and should be accessible from within the package
        // otherwise define it to be at least protected
        // With static class you can call:
        // new SingleClassWithOneStaticMember.StaticMember();

  • Selection problem in a JList !!!!

    I am using a JList and on the selection of an item in this JList - I enable and disable some buttons.
    I have currenlty added a ListSelectionListener that allows me to trap the valuechanged event and thus if any item in the list is selected / deselected, i can enable/ disable the buttons.
    Now the abuv works fine with click and Ctrl clicking (to deselect),
    However if i come into the JList from another control (a JCombo) by tabbing and then use the arrow keys once the control is in the JList, the up and down arrow keys allow me to change the selection in the list.
    But, the valueChanged event does not come in the above case and hence the buttons do not enable/disable !!!
    Can you tell me what can be the problem?????

    Add a key listener and handle the KeyEvent
    Sachin

  • Problem in multiple selections in a jList

    I have two jLists. Now I have to select some items from one jlist and have to transfer in the other one. But while trying to do it in the runtime I am getting some unexpected runtime errors including "Exception occurred during event dispatching". When I try to transfer only one item it works fine but shows problem in multiple selections. Pleast give your suggestions.

    [_First suggestion_|http://catb.org/~esr/faqs/smart-questions.html]
    [_Second suggestion_|http://mindprod.com/jgloss/sscce.html]
    db

  • Problem in displaying images one by one in JList

    I have a problem in displaying images one by one in Jlist. I want to show 100 images as a thumbnailview in jlist but it is talking too much time to show all the images after scalling 100 images to thumbnail view and making it into ImageIcon. So, i thought that it would be better way to show one by one after scaling it into thumnailview. But my renderer is getting calling after 100 images scaled down and setting into list. I have posted my code 2 days back but there is no reply.
    http://forum.java.sun.com/thread.jspa?threadID=789943
    I donno where i am missing in this code.
    Plz suggest me some solution for it.

    Where is the scaling done? In the ListCellRenderer? Regardless of where that is being done, I assume you are caching the scaled images after you scale them, right? If not, consider adding some sort of caching.
    This should do the trick...
    Rework your ListCellRenderer to check to see if a scaled version of the image is available. If not, start a thread to do the scaling and create an ImageIcon. In the meantime, while that thread is running, have the renderer return some sort of stock icon, like a little generic image icon. When the scaling thread completes, make a call to repaint() on the JList so the cell renderer gets re-asked for the icons. This time around, the renderer should notice that a scaled version (the ImageIcon) is available. Return that. So, this method doesn't guarantee that the images will be produced in order, 1...2...3..., but it will return images as they become available, and the overall JList rendering won't wait until all 100 are ready. If you want them returned in order, just do all of the scaling in a single thread and queue up the images to be scaled, in order.
    I hoped this helps. (If it does, please throw me some Duke Dollars.)

  • Problem- Set TransferHandler for JList

    Hi all,
    In the attached code, I set transfer handler to a Jlist. But when I click and drag it, the string given in println is not printed.
    This is the initial step which I did for set transfer handler to jlist and I believe it should get printed.
    Please point out if I have made any mistake in this.
         jlist.setTransferHandler(new TransferHandler()
                   List fileList;
                   boolean export = false;
                   List<File> newList = null;
                   protected Transferable createTransferable(JComponent c)
                        System.out.println("You entered create transferable");
                                    ........................................................Regards,
    Anees

    Hi,
    Did you tryjlist.setDragEnabled(true);
    Exactly that was the problem. Thanks mpmarrone .
    Also, camickr, after reading the tutorials only I posted this thread. Somehow, I missed this valuable point. Anyway thanks alot for your helping attitude.
    Anees

Maybe you are looking for

  • Set up a family with Apple Products

    What is the best way to set up a family with multiple apple products? Equipment: My wife and I each have iPhone v4s We have an AppleTV version 1 and an AppleTV version 2 iPad 2 NAS in the closet with iTunes server (which we don't utilize) iTunes inst

  • Printing Templates

    I have the HP 8600 All-in-one Premiun printer.  When I try to use a template in Microsoft Word, the background doesn't show up, only  the text that I've put in the template.  What am I doing wrong?

  • Print image shifted?

    I own an HP Photosmart A524 photo printer. Before you tell me that HP has no info on this printer on their website, let me explain that I bought it as a kit (called HP Photosmart Compact Photo Studio) with a camera (HP Photosmart M447) from WalMart.

  • .AVI conversion to Apple TV issue

    Hi folks. There are different replies on the message board - somewhat confusing to go thru them all and not all of them seem to be exactly like mine. I have a bunch of .avi movies I'd like to convert and put in iTunes for my Apple TV. Most of the mov

  • ATV zone 2 issues with Yamaha A700 receiver

    Short time lurker, first time poster. In any event, I recently purchased ATV and hooked device to my Yamaha A700 receiver at HDMI input 3. Sound and video quality if perfect when streaming to zone 1. However, when attempting to push music to zone 2..