jlist

Cannot add checkbox to the JList

爷,独闯天下 提交于 2019-11-27 08:43:22
问题 I'm very new to programming, and I can't add JCheckbox to the JList . There is no error but nothing is displayed. JFrame f=new JFrame(); String[] labels={"a","b","c","d","e"}; JCheckBox[] ch=new JCheckBox[labels.length]; JList list=new JList(); for (int i = 0; i < labels.length; i++) { ch[i]=new JCheckBox("CheckBox"+i); list.add(ch[i]); } JScrollPane pane=new JScrollPane(list); f.add(pane); f.setVisible(true); 回答1: A JList renderer can draw a checkbox, but JList does not support a cell editor

Reordering JList with Drag and Drop

馋奶兔 提交于 2019-11-27 07:39:40
问题 I encountered a problem regarding reordering elements in a JList using Drag and Drop. This following code is a modification of a code where you could drag elements from one JList to another (worked only one way). I tried to make it usable for only one JList, but the elements can't even be dragged out of the list. So I guess it can't be done this way. Any ideas what I'm doing wrong or not taking into consideration? The idea is to get it to work for a Jlist with thumbnails, but since I can't

Is there something wrong with Swing's MVC implementation for JList?

你离开我真会死。 提交于 2019-11-27 07:37:59
问题 Some time ago I asked this question. All solutions are workarounds. Now this can't be. I feel that something is wrong here, but I can't tell if it is Swing's MVC model that is conceptually wrong, or if it is my thinking that is conceptually wrong. Here is the problem again. I am using a JList to implement a list of thumbnails for the pages of a document. If the user selects another thumbnail from the list, that page is loaded. To do this I added a ListSelectionListener to the JList , which

Adding elements to a JList

纵饮孤独 提交于 2019-11-27 06:19:10
问题 I have an array of objects that contain the name of customers, like this: Customers[] How I can add those elements to an existing JList automatically after I press a button? I have tried something like this: for (int i=0;i<Customers.length;i++) { jList1.add(Customers[i].getName()); } But I always get a mistake. How I can solve that? I am working on NetBeans. The error that appears is "not suitable method found for add(String). By the way my method getName is returning the name of the customer

Java ArrayLists into JList

风格不统一 提交于 2019-11-27 05:56:33
问题 OK so I'm doing a small part of my inventory. I got MOST of it down. I'm trying to add string items to an ArrayList then add that to a JList. However, I'm getting this error when I compile: C:\Users\Dan\Documents\DanJavaGen\inventory.java:30: cannot find symbol symbol : constructor JList(java.util.ArrayList<java.lang.String>) location: class javax.swing.JList list = new JList(arr); It's probably some rookie mistake I am making ... :/ Code: import java.applet.Applet; import java.awt.*; import

How can I set the priority mouse listener

安稳与你 提交于 2019-11-27 05:32:28
I have a panel with lists and buttons. The lists set MouseAdapter with mouseClick() . I added to the panel MouseAdapter with mousePressed() and mouseReleased() and MouseMotionAdapter with mouseDragged . Drag and drop only works if you click on the panel. How to make the drag work even if I clicked on the list? Simple examlpe: public class DragTest extends JFrame{ private boolean drag; private Point btnCoord; private Point startPoint; public DragTest(){ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(500,500); setLayout(null); final JPanel panel = new JPanel(); final JButton

How to create JList with icon and text?

百般思念 提交于 2019-11-27 04:42:05
问题 I have this code want to make JList talk text and icon what must to do. Some persons advice me to make list of label and in table put text an icon is it Possible? How? Search on ///////////////// for embedded comment. import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.dnd.DropTarget; import java.awt.dnd

Refresh JList in a JFrame

Deadly 提交于 2019-11-27 03:47:34
问题 I've got a JList which displays information from a vector. The user can then add and remove information from this vector. Is it possible to refresh the JList inside my JFrame when items are added / removed from the Vector? Currently I'm doing.. list = new JList(names); jframe.add(new JScrollPane(list), BorderLayout.CENTER); but this doesn't refresh the JList to anything new. I've check and my vector contents etc. do change but the list isn't refreshing. Why? how can I fix it? 回答1: You should

Double-click event on JList element

独自空忆成欢 提交于 2019-11-27 00:31:21
问题 I have a JList with a DefaultListModel . How I can make an item in a JList react to double-click event? 回答1: String[] items = {"A", "B", "C", "D"}; JList list = new JList(items); list.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { JList list = (JList)evt.getSource(); if (evt.getClickCount() == 2) { // Double-click detected int index = list.locationToIndex(evt.getPoint()); } else if (evt.getClickCount() == 3) { // Triple-click detected int index = list

JList that contains the list of Files in a directory

醉酒当歌 提交于 2019-11-26 22:24:42
问题 I created a JList that contains a list of files that are in a directory. Here is the JList . JList MList; String ListData[] // Create a new listbox control List = new JList(ListData); I also created a method that reads a list of text files in a directory: public String ReadDirectory() { String path = "C://Documents and Settings/myfileTxt"; String files = null; File folder = new File(path); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles