Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Drag & Drop: how to remove from the list  RSS feed

Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
my code is below. I have a list of days and the user can click a day and drag it to a 'slot'.

1. When the user drag it to a different slot, the date still appears on the list - how can i remove it.

2. I don't want the user to chage the name of the date (once he moves it to a diff slot) how can I restrict him? (i tried setEditable(false) but it will not allow me to drag the day there.


import java.awt.*;
import javax.swing.*;
import java.text.*;
import java.util.*;

public class Drag1 {
public static void main(String args[])
JFrame frame = new JFrame("Drag");

Container content = frame.getContentPane();
JPanel inner = new JPanel(new BorderLayout());
JTextArea top = new JTextArea(5, 40);
JScrollPane topScroll = new JScrollPane(top);
inner.add(topScroll, BorderLayout.NORTH);
JTextArea bottom = new JTextArea(5, 40);
JScrollPane bottomScroll = new JScrollPane(bottom);
inner.add(bottomScroll, BorderLayout.SOUTH);
content.add(inner, BorderLayout.CENTER);
DateFormatSymbols symbols =new DateFormatSymbols(Locale.US);
JList list = new JList(symbols.getWeekdays());
JScrollPane leftScroll = new JScrollPane(list);
content.add(leftScroll, BorderLayout.WEST);
Constanze Michaelis
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i never worked on JLists, but for your first question, what about removeSelectionInterval(int index0, int index1) ?
or did i understand it not correctly
the 2nd question i hop someone else will help you.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!