• Post Reply Bookmark Topic Watch Topic
  • New Topic

Drag & Drop: how to remove from the list

 
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'.

Questions:
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.

thanks
Ppr



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");
frame.setDefaultCloseOperation
(
JFrame.EXIT_ON_CLOSE
);

Container content = frame.getContentPane();
JPanel inner = new JPanel(new BorderLayout());
JTextArea top = new JTextArea(5, 40);
top.setDragEnabled(true);
JScrollPane topScroll = new JScrollPane(top);
inner.add(topScroll, BorderLayout.NORTH);
JTextArea bottom = new JTextArea(5, 40);
bottom.setDragEnabled(true);
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());
list.setDragEnabled(true);
JScrollPane leftScroll = new JScrollPane(list);
content.add(leftScroll, BorderLayout.WEST);
frame.pack();
frame.show();
}
}
 
Constanze Michaelis
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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.
regards
constanze
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!