The Artima Developer Community
Sponsored Link

Java Answers Forum
Copying icon and string from one JList to another JList

3 replies on 1 page. Most recent reply: Feb 23, 2004 3:01 PM by Daniel Liu

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Daniel Liu

Posts: 11
Nickname: hhliu
Registered: Feb, 2004

Copying icon and string from one JList to another JList Posted: Feb 21, 2004 9:21 AM
Reply to this message Reply
Advertisement
Hello,

I need copy icon and string from one JList to another JList.

All the icons and strings are already shown in the first JList on the interface. But, when I select the icon and string from the first JList and then click the add button, the second JList shows: null (no image available).

The following is the code segment, could any one help have a look and find the problem?

imageList = new JList(intArray);
imageListRenderer imageRenderer= new imageListRenderer();
imageRenderer.setPreferredSize(new Dimension(200, 125));

imageList.setCellRenderer(imageRenderer);
imageList.setVisibleRowCount(7);
imageList.setFixedCellHeight(125);
imageList.setLayoutOrientation(JList.HORIZONTAL_WRAP); imageList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
JScrollPane imageScrollPane1 = new JScrollPane(imageList);

imageScrollPane1.setPreferredSize(new Dimension(1000, 260));
panel2.add(imageScrollPane1);

personModel = new DefaultListModel();
personList = new JList(personModel);

personListRenderer personRenderer= new personListRenderer();
personRenderer.setPreferredSize(new Dimension(200, 125));
personList.setCellRenderer(personRenderer);

personList.setVisibleRowCount(3);
personList.setFixedCellHeight(125);

personList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);


JScrollPane personScrollPane1 = new JScrollPane(personList);

personScrollPane1.setPreferredSize(new Dimension(200, 260));
panel9.add(personScrollPane1);

// handle button events
public void actionPerformed( ActionEvent event )
{
if (event.getSource() == addPersonButton)
{
personModel.addElement(imageList.getSelectedValue());
}
}

Thanks,

Daniel


Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: Copying icon and string from one JList to another JList Posted: Feb 23, 2004 5:06 AM
Reply to this message Reply
try to use the java API under Package
java.awt.datatransfer

it may help you..

Viswa
--------

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Copying icon and string from one JList to another JList Posted: Feb 23, 2004 7:31 AM
Reply to this message Reply
One probabilty can be your condition
if (event.getSource() == addPersonButton)
{
}
is not getting satisfied and the control is not going inside this condition.

Try a System.out.println() inside the condition to make sure that the cntrl goes into the if condition.

Check http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.html#ListDemo

for list demo

Daniel Liu

Posts: 11
Nickname: hhliu
Registered: Feb, 2004

Re: Copying icon and string from one JList to another JList Posted: Feb 23, 2004 3:01 PM
Reply to this message Reply
I added
System.out.println("addPersonButton clicked");
into
if (event.getSource() == addPersonButton)
{
}

When I click the addPersonButton on the interface,
the string "addPersonButton clicked" was printed.

So, the condition of the button works.

Flat View: This topic has 3 replies on 1 page
Topic: Adding Sound to Application Previous Topic   Next Topic Topic: Print a image(bitmap or JPEG)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use