FAQ Database Discussion Community


Actionlistener outputing Jlist info to textarea

java,swing,actionlistener,jlist,thread-sleep
Could someone help me with the following problem? I want to implement a actionlistener that outputs info about the highlighted Jlist object into the already present textarea. Here is the code i've managed to cook up: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ListModel extends JFrame { private JList...

The method add(String) in the type ArrayList is not applicable for the arguments (Object)

java,string,arraylist,jlist
I am running the following code: public ArrayList<String> equipAvail; { equButton2 = new JButton(); equButton2.setText("Apply"); equButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { //read the contents of equlist2 for(int i=0;i<equList2.getModel().getSize();i++){ //fill equipAvail ArrayList with the contents of equlist2 //System.out.println(equList2.getModel().getElementAt(i)); //System.out.println(equList2.getModel().getElementAt(i) instanceof String);...

JList Left Attached and Filled

java,eclipse,swing,jlist
setLayout(new BorderLayout()); add(listScroller, BorderLayout.WEST); When i just do this my list being left attached and filled all column size. But when i add more things. setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.gridx = 2; gc.gridy = 0; add(nameLabel, gc); It's being smaller and when i resize it turns...

How to link two jComboBoxes together and display the data into a jtextarea?

java,swing,jcombobox,jtextarea,jlist
My question is how to link two comboboxes together. The reason being that I want the user to be able to choose a manufacturer brand and for the next combobox to display the cars linked to that manufacturer. Then I want the data to be put into a jtextarea to...

Removing items from a JList

java,swing,jlist
here is a code , I want to change JList items, but when i click on open button and JList.removeAll() runs , my JList doesn't remove items... what is the problem? import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JListTest { public static void main(String[] args) { String[] j =...

JList repeatedly updating defaultlistmodel after selecting item 0

java,swing,jlist,defaultlistmodel,listselectionlistener
I am using the Swing designer in Eclipse to build a GUI to list my movies which are stored in an XML file. After loading the frame and contents to the various JLists, I have the app set to update the lists when an item is selected. So, if you...

JList list items squashed

java,jframe,jpanel,jscrollpane,jlist
I've got my JList working, but only the first list item is its proper size. Everything else under it is squashed. I have searched all StackOverflow and haven't found much (getting it to work was all StackOverflow though) package networks; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File;...

Unable to get each item from selected multiple line Jlist?

java,swing,jlist,defaultlistmodel,listcellrenderer
After doing lots of research i am still unable to get items from selected multiple line jlist. Here is my code for listSelectionListener: list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { ListModel model = list.getModel(); for(int i=0; i < model.getSize(); i++){ System.out.println( model.getElementAt(i)); } } }); I also added a...

DefaultListModel in Java modifies a String passed as an argument to addElement method

java,string-formatting,jlist,defaultlistmodel
I am facing an interesting issue trying to output POJO loaded from a database into JList using DefaultListModel. Briefly, this is my code: // load POJO objects from the DB PersonData[] allUsers = loadAllUserData(); DefaultListModel listModel = new DefaultListModel(); // fill in (with) the data for (int i = 0;...

JTable JComboBox is defaulting to display 1st item when list is expanded

java,swing,jtable,jcombobox,jlist
I have been trying to determine why my JComboBox is displaying the 1st item in the list through numerous Google searches, but I'm struggling to find relevant help. It could be that I don't know the correct terminology (hence the overly specific title of this question) and thus not finding...

JList gets updated but just allow users to select items once

java,swing,jlist
I have a JList that is located in a JScrollPane. The application has a button for users to browse fileSystem and select a category to show its files and folders. First time user clicks on the button JList shows the list and enables user to select from the list but...

Java - Correct way of add a ConcurrentHashMap to a JList?

java,thread-safety,jlist
Here is my example code: Person Class: public class Person { private String firstName; private String lastName; @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); result = prime * result +...

How to select an item from a JList without using a button?

java,swing,jlist
I've been making a program, and one part of it is the ability to choose an item from a JList and have it display a specific icon in a JLabel. I've made it work so that the user has to select the item from the list and then press a...

Increase time to typing and find an element in JList

java,swing,jlist,jcomponent
I have a JList and this component has a lot of items. If I type some text, an element was selected. For example, if I have this elements: element1 initialElement lastElement partElement poorElement overElement And if I enter "p", the "partElement" was selected. If I enter "po", the "poorElement" was...

Issue With Java JList

java,jlist
I have tried to use a Jlist but I have not been able to get it to show up in my JFrame. Here is my code: private static void list(){ JFrame frame = new JFrame(); frame.setTitle("Menu"); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setLayout(new FlowLayout()); listModel = new DefaultListModel(); listModel.addElement("Add Member"); listModel.addElement("Add Meeting");...

Adding JList to show basic DB information

java,database,jlist
My goal is to put a JList with the data from my DB over the 2 JTextFields, but i dont know how to do it. Do you guys and girls know what the mistake is and how I can fix it? (The Variable personList has all the Data in it....

How to get a right-click item which is not selected in Java Swing's list?

java,swing,mouseevent,jlist
I have a Java Swing Jlist, and I know how to process a left-click and right-lick on a "selected item", but my question here is : If item 1 is currently selected, but when I right click on item 3, how to get that item's info/identity ? For example, in...

Activity Diagram and SwimLanes

uml,jlist,activity-diagram
Should activity diagram include detailed information about how the system functions from the start of the application? Say for example i am making a swing application in which the app loads a JList with images when the application opens, so should i specify that in activity diagram even though user...

How to prevent selection of SeparatorList.Separator in a JList?

java,override,selection,jlist,glazedlists
I have created a JList using GrazedLists, specifically an EventList which I then pass into a SeparatorList with a custom Comparator that sorts my EventList elements. I am using a DefaultEventListModel as the JList model, passing in my SeparatorList. And I am using a custom CellRenderer to decorate the SeparatorList.Separator...

Get multiple selected items from a JList

java,swing,jlist
I am creating a screen with four lists on it. Basically two pairs of lists where you can select lines on one list in the pair and move them to the other list in the pair. Looking at the documentation I need a ListSelectionModel for each list to determine which...

Can't add to my JList?

java,swing,jlist
I've a class called PlaceCategory, which have a name and a color. And when I want to create a new PlaceCategory I first enter the name of it and then choose a color. They are saved to a String and a Color. And when I'm done I create a new...

Swing: JList holding multiple Components as a single item

java,swing,jtable,jlist,imageicon
Here is my problem: I'm creating a window that is responsible for listing a layer, where it displays the layer's current image (in the form of a ImageIcon as of now), layer's name, and a check box to alter the current on/off state of said layer. The entire thing is...

JList how to remove an Item in simple way?

java,jlist
I know there are some questions related to this but they did not help me at all my code is simple I'm trying to delete the first item on my list DefaultListModel model = (DefaultListModel) jList1.getModel(); model.removeElementAt(0); this gives me a ClassCastException as follows Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: rfs.search$1...

Delete File from Jlist

java,swing,file,delete,jlist
Don't know what I'm doing wrong here. I'm trying to delete the selected file from my directory but it's only deleting it from the list. Thanks private void deletecustButtonActionPerformed(java.awt.event.ActionEvent evt) { DefaultListModel model = (DefaultListModel) customerList.getModel(); int selectedIndex = customerList.getSelectedIndex(); File customer = new File("Customers/" + selectedIndex); if (selectedIndex !=...

Select from jlist and update jtable using checkbox

java,swing,jtable,jlist,jcheckbox
ive made a java program inside that i have 2 jlists(Main Category and Sub Category) and a jtable that retrieves values from mysql database , in the jtable there an extra column for checkbox , when the user selects a couple of rows and selects values from the jlists than...

Jlist binded from DefaultListModel is it possible to Display Only Certain elements ?

java,swing,jlist,defaultlistmodel
Is it possible to bind or show only some of the ListModel or List When i Bind it to a Jlist item ? In my Example I have a list model made from an array of a class(pizza) which has multiple variable's I only want to show one, but they...

Why can't I get to mouse click count == 2 first in Java?

java,swing,jlist,click-counting
In my Java Swing app, I have a JList, and when I double click on an item in the list, it always does click count == 1 things first then do things in click count == 2, why ? list.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) {...