jlist

Java - How do I get a all the selected values from a JList?

耗尽温柔 提交于 2019-12-21 09:02:10
问题 A struggling Java newbie here - help! I'm trying to: - Get all the selected values from a JList - Create an ArrayList from those values It seems getSelectedValues is deprecated? 回答1: Until JDK 1.6 (deprecated in 1.7): public Object[] getSelectedValues() New since JDK 1.7: public List<E> getSelectedValuesList() Returns a list of all the selected items, in increasing order based on their indices in the list. 回答2: As of JDK1.7 it was replaced with public List<E> getSelectedValuesList() . http:/

Java drag and drop images in a list

孤街浪徒 提交于 2019-12-21 04:18:11
问题 I am looking for a way to display a series of pictures (JPanels with image and maybe some other small components), in a horizontal sequence. The user should be able to rearrange the order of the images, by drag and drop. How do I do this? Is JList with some custom components and D&D the way to go? Some issues to think about (having the components the same dimension increases performance I've heard). 回答1: The following example shows you how to show images horizontally in a list and use drag &

is Jlist Override the List automatic? (bug)?

走远了吗. 提交于 2019-12-20 07:46:20
问题 I hope I will get help, I will ask as general question: I am using a JList , and due to the JList not have a (value,text) (so I can display text and use the value in my code). Because of this leak I create List of object (myList), that work parallel with the JList . Every item I add to JList I add to myList , so the same index will contain the same info in the two objects (JList and mylist) I use the JList.getselectedindex() method to get the index and use it in myList to pup information...

Writing something in JList

与世无争的帅哥 提交于 2019-12-20 07:27:11
问题 hey i have another problem. I created JList in my main window and now i want to add something to it. I do it this way... private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { Dodaj_Przedmiot dodaj_przedmiot = new Dodaj_Przedmiot(null, true); dodaj_przedmiot.setVisible(true); SterowanieBazy instance = SterowanieBazy.getInstance(); Zmienne_pomocnicze zp = new Zmienne_pomocnicze(); String przedmiot = zp.getPrzechowaj(); instance.dodajPrzedmiot(przedmiot); String przedm[] =

Java, putting a JScrollList onto a JPanel

早过忘川 提交于 2019-12-20 07:06:49
问题 I am wondering if there is a way to add a JList on a JFrame with a JPanel. I am making a program and I searched all over the interwebs for an answer but I can't find one. Anyways Preferably the JList with a scrollpane (that works) if it is possible Here is my code: public static void main(String args[]) { JScrollPane scrollpane; JFrame frame = new JFrame(); JList list; String categories[] = { "1", "2", "3","4", "5", "6", "7","8", "9", "10", "11", "12" }; list = new JList(categories);

Java, putting a JScrollList onto a JPanel

余生颓废 提交于 2019-12-20 07:03:50
问题 I am wondering if there is a way to add a JList on a JFrame with a JPanel. I am making a program and I searched all over the interwebs for an answer but I can't find one. Anyways Preferably the JList with a scrollpane (that works) if it is possible Here is my code: public static void main(String args[]) { JScrollPane scrollpane; JFrame frame = new JFrame(); JList list; String categories[] = { "1", "2", "3","4", "5", "6", "7","8", "9", "10", "11", "12" }; list = new JList(categories);

JList not updating when adding element to DefaultListModel

不羁的心 提交于 2019-12-20 05:18:13
问题 I'm trying to create a simple program to manage Employees. When trying to add a new employee I can't seem to get the employee to be displayed on the Jlist. The main frame... public class EmployeeFrame extends JFrame implements ActionListener { // The buttons to display private JButton addButton; private JButton editButton; private JButton deleteButton; private JButton saveButton; // The underlying list of employees, and the GUI object to display them private DefaultListModel<Employee>

Java Swing Updating JList

南笙酒味 提交于 2019-12-20 04:15:55
问题 I'd like to know if there is any way that I can update a Jlist after the user adds or removes an item to it and after a user sorts it. Is there any way that I can write a standardized method to update the display based on the order of items in an array or vector, and when the user remove or adds an object from the array that the JList is based on? Thank you. 回答1: Updates should be made to the ListModel, not the Array that was used to create the model. However, if you want to refresh the list

How to set .TIF image to ImageIcon in java?

荒凉一梦 提交于 2019-12-20 03:46:05
问题 Could anyone suggest me how to store .TIF formatted image to ImageIcon and add this image to list model? I tried this but gives me java.lang.NullPointerException . public static void main(String[] args) throws Exception { String path = "C:\\project\\aimages"; JFrame frame = new JFrame(); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); File folder = new File(path); File[] listOfFiles = folder.listFiles(); DefaultListModel listModel = new DefaultListModel();

Can I set the selected item for a JList without having an event thrown to the listeners?

谁说我不能喝 提交于 2019-12-20 01:32:08
问题 I am working on a viewer, which uses a JList to show thumbnails of the pages of a document. The user can open a page by selecting it through in the JList, or throught other mechanisms, like entering the number in a text box. When using the latter alternative, I want that the JList also selects the page. I do this using setSelectedIndex(), but this triggers an event, which causes the page to be loaded again, as if the user had clicked and selected the page in the JList, and this is causing me