jlist

inside JButton's actionperformed final variables required? [duplicate]

谁说我不能喝 提交于 2019-11-28 13:01:20
This question already has an answer here: Cannot refer to a non-final variable inside an inner class defined in a different method 20 answers So i have a JList and i am trying to use it inside of a JButton s actionPerformed method and it is asking me to make the JList final why is that, below is a code snippet public SomeClass() { btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { list.clearSelection(); }}); } I don't actually have a problem making it final, I just am not sure why i would need to. To answer your question, you need to understand

Getting multiple files from JFileChooser

早过忘川 提交于 2019-11-28 12:47:53
In a GUI app that I am working on, I require to select multiple files but instead of directly opening it with the File chooser I first need to add all required files in a Selected list (so that instead of selecting files again and again from different directories I can select them all at a time and then open all the files added to that list). Moreover I should also be able to remove multiple files from those present in that Selected File list too. Is that possible with JFileChooser or do I need to design one as per my requirements? What you are looking for is not a standard feature, but you

how to bind ArrayList to JList

纵饮孤独 提交于 2019-11-28 12:30:37
i have a JList and an ArrayList.How to bind the datas in arraylist to the jlist.Are the any alternative methods? ArrayList arl = new ArrayList(); arl.add("1asdsd"); arl.add("2asdsd"); arl.add("3asdsd"); Object obj = arl.clone(); JList list = new JList(obj); how to bind the above code.Now the code give an error. You don't need to clone the ArrayList. Just call toArray() JList list = new JList(arl.toArray()); ArrayList<String> aList = new ArrayList<String>(); aList.add("blabla"); aList.add("blublu"); aList.add("blibli"); aList.add("bleble"); DefaultListModel<String> model = new DefaultListModel

Adding elements to a JList

点点圈 提交于 2019-11-28 11:36:09
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 in a String. The add method you are using is the Container#add method, so certainly not what you need.

Problem with reusing the JScrollPane again for different custom Lists

若如初见. 提交于 2019-11-28 11:13:50
问题 I am trying to create a JScrollPane component which can be reused depending upon the string parameter that is being passed.. I have created the following code, it works if I use JFrame to embed the JScrollPane inside it, but when I try to reuse the code in creating different JScrollPane the scrollPane is not displayed at all.. I am implementing it in a java swing project.. Please let me know what should be done in this..any suggestions are highly appreciated. The same problem I have with

Java ArrayLists into JList

江枫思渺然 提交于 2019-11-28 11:03:41
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 javax.swing.*; import javax.swing.JList; import java.awt.event.*; import java.util.ArrayList; import

Delete selected item from JList

為{幸葍}努か 提交于 2019-11-28 11:02:06
Can anyone tell me a short way to delete the selected items from my JList ? I searched on google and here, but I found very many ways. Which way should I use? As @Andreas_D said, the data centered, more abstract ListModel is the solution. This can be a DefaultListModel . You should explicitly set the model in the JList. So (thanks to comment by @kleopatra): DefaultListModel model = (DefaultListModel) jlist.getModel(); int selectedIndex = jlist.getSelectedIndex(); if (selectedIndex != -1) { model.remove(selectedIndex); } There are several remove... methods in DefaultListModel. By the way, this

JList - deselect when clicking an already selected item

断了今生、忘了曾经 提交于 2019-11-28 10:04:01
If a selected index on a JList is clicked, I want it to de-select. In other words, clicking on the indices actually toggles their selection. Didn't look like this was supported, so I tried list.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { java.awt.Point point = evt.getPoint(); int index = list.locationToIndex(point); if (list.isSelectedIndex(index)) list.removeSelectionInterval(index, index); } }); The problem here is that this is being invoked after JList has already acted on the mouse event, so it deselects everything. So then I tried removing all of JList

JList add/remove Item

♀尐吖头ヾ 提交于 2019-11-28 07:30:35
问题 Hi I have to pick an element from a JList to another, removing it from the first The method I've created inserts only one element, overwriting the last one and doesn't remove the selected item from the first JList Here's the code: First list private javax.swing.JList listaRosa; Populated by this method: private void visualizzaRosaButtonvisualizzaRosa(java.awt.event.ActionEvent evt) { // TODO add your handling code here: visualizzaSquadraSelezionata(); String fileSquadra; fileSquadra =

Java AWT Threads

妖精的绣舞 提交于 2019-11-28 02:04:23
I'm having an issue with Threads using netbeans Swing GUI. This is my first time really trying to develop a GUI for a backup program using Java's File System Notifier. I have two files SyncUI.java and Sync.java . Pretty much what I want to happen is you enter a directory path in the jTextField1 text field which creates a sync thread that creates a new sync object and then calls processEvents on that object. When a file in that directory is changed I want to add text about the change to the list. In its current state the UI is no longer not responding, however the processEvents isn't adding