The default renderer of a JList simply displays the toString() implementation of the object that you add to the model. Don't add a JTextArea to the ListModel. Add the String to the ListModel Also, why are you using "select * from Teams" when you only want a single column of...
java,string-formatting,jlist,defaultlistmodel
It's not the spaces, it's the font -- the console is monospaced, and Swing uses something else (Arial?) by default. As discovered in the question comments, you can simply change the default Swing font to a monospaced font with: list.setFont(new Font("Monospaced", Font.PLAIN, 12)); to have it match the console formatting...
java,swing,user-interface,jtextfield,jlist
Regarding your questions: The problem I'm having is trying to figure out how I can pass all the customer's data from the text-fields in the 2nd GUI and transfer them into the JList in the 1st GUI... There are usually two problems in this situation -- How to get the...
First of all , the BorderLayout Parameters use only when the layout is BorderLayout. You can use GridBagLayout Instead. Sample code is below setLayout(new GridBagLayout()); add(new JButton("add"), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); add(new JButton("Check In"), new GridBagConstraints(1, 1, 1,...
You need to add an ActionListener to your Delete button. You have one but it's commented out. In this listener, you need to determine which items to keep/discard. In your attempt, you iterate over the JList's selection model. Instead, you need to iterate over it's data model. When you...
A ListSelectionListener will generate multiple events every time the selection changes. You need to check the ListSelectionEvent.getValueIsAdjusting() to make sure the selection is finished adjusting if (!event.getValueIsAdjusting()) // create your internal frame. ...
While not the most elegant way, you can add a FocusListener to your Jlists public class CheckFocus extends JFrame { JList<String> focusedList = null; JList<String> list1 = new JList<>(new String[]{"A", "B"}); JList<String> list2 = new JList<>(new String[]{"1", "2"}); CheckFocus() { JButton btn = new JButton("Who has focus?"); btn.addActionListener(new ActionListener() {...
java,jframe,jpanel,jscrollpane,jlist
Don't use an array for the data. Your array contains null values, except for the first entry. The null entries are being rendered funny. Instead use the DefaultListModel and add items directly to it: DefaultList model = new DefaultListModel(); model.addElement( "line1" ); JList list = new JList( model ); ...
java,override,selection,jlist,glazedlists
Through some trial and error, based on the code suggestions that I found at http://stackoverflow.com/questions/8344393/disable-items-in-jlist and building up on them, I was able to put together something that is now working quite well. I had to change around the logic in the linked example. Basically I walk between the selected...
Your problem is that your Thread.sleep(...) and while (true) loop are both tying up the Swing event thread preventing it from doing its two main jobs of drawing the GUI and interacting with the user. This will effectively freeze your GUI. You could use a Swing Timer to do your...
java,swing,jlist,defaultlistmodel
The default cell renderer is calling toString() on the value objects in your model. You can do either of these: Override/change the value returned by toString() to be the text you want to show Change the cell renderer to format the value object differently from the default I'd prefer the...
java,swing,class,arraylist,jlist
You need to implement custom cell renderers, which would be a good idea anyway (in any real-world application). The renderer (a swing component) will get the Contract object and can grab the house data from there. Here is tutorial from Oracle. Advanced: you can mix classes in the model and...
java,swing,user-interface,jcombobox,jlist
You add an ActionListener to the combo box. Then when an item is selected you update the JList with a new ListModel. Here is an example with two combo boxes, but the concept would be the same with a combo box and a JList. import java.awt.*; import java.awt.event.*; import java.util.*;...
should I depending on value from JComboBox 'switch' between JList and JTree? Yes. Unless you can think of a better way. And how would I do that without messing with layout(I am using GridBagLayout) Put a panel where the list is now. Give the panel a CardLayout1. Add the...
addElement is provided by the DefaultListModel not the JList itself DefaultListModel<String> model = new DefaultListModel<>(); JList jListResult = new JList(model); model.addElement(...); ...
java,swing,jlist,defaultlistmodel,listselectionlistener
You are modifying the lists while selection is still in progress, which causes additional selection events to be fired (recursively). You are also modifying both lists for no reason. The String list should just act as a filter to the Integer List. Also, I don't understand why you're removing all...
java,swing,jtable,jlist,imageicon
JList is a generic class. Create a class which extends JPanel. (Let us call it RowPanel) Put all elements in it required to be present in a single row (using a horizontal layout) Create your JList using those panels like JList<RowPanel> list = new JList<RowPanel>(); You can refer to this...
java,swing,actionlistener,jlist
I'm trying to add an actionListener to a JList, You can't, it doesn't have ActionListener support so whenever a user click a value in the JList , it will just println the value. Use a ListSelectionListener instead Take a look at How to Use Lists and How to Write...
java,swing,listbox,applet,jlist
To select multiple elements, you can to use something like JList#addSelectionInterval, for example... import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.DefaultListModel; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class ListSelectionExample { public static void main(String[] args) { new ListSelectionExample(); } public ListSelectionExample() { EventQueue.invokeLater(new Runnable() {...
Override the toString() method in your Catalogue class: @Override public String toString() { return getName(); } ...
Per ConcurrentHashMap's documentation: Similarly, Iterators and Enumerations return elements reflecting the state of the hash table at some point at or since the creation of the iterator/enumeration. They do not throw ConcurrentModificationException. However, iterators are designed to be used by only one thread at a time. So if you are...
You do not need a listener, a listener is only useful for keeping something in sync elsewhere, which you don't need. You can access the selected indexes at any point after the selection event(s) occurs. The method JList.getSelectedIndices returns an array of currently selected indexes, and getSelectedValuesList() returns the actual...
A JList cannot hold components, but instead can only hold renderings of a component. So in short, your request is not directly possible. But, you can have something similar with a JTable that holds editable renderings of JButton and your JProgressBar and JLabel. The big difference with the JTable is...
Here is my code: import java.awt.BorderLayout; import java.awt.Container; import java.awt.FlowLayout; import java.util.ArrayList; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; public class Example extends JFrame { JList list = null; Example() { Container cp = getContentPane(); cp.setLayout(new FlowLayout()); ArrayList data = new ArrayList(); data.add("Py"); data.add("Piper"); list = new...
java,hashmap,jbutton,jtextfield,jlist
Yes you can put the value from two JTextField s to the HashMap lm by using this code. String key=keyTextField.getText();//This will retrieve the value of JTextField keyTextField and store it to the String variable key. String value=valueTextField.getText(); hashMap.put(key,value);//This will store the value variable with identifier variable key into the HashMap...
This is a common and accepted method of handling this situation.
Don't remove from the JList itself since the remove(...) method does not do what you think that it does. It in fact is trying to remove a component that is held in the JList as if it were a JPanel that held other components, even if no such component exists....
for (int i = 0; i < mModel.getSize(); i++) You need to start at the end of the list and work backwards: for (int i = mModel.getSize() - 1; i >=0; i--) because if you start at 0, all the rows will shift down by one when the row is...
java,swing,jlist,mouselistener
listPL and listRN should not have the same ListSelectionModel, when you select an item in the first list it's added to the second list and the selected item within it is changed so also the selected item of the first list is changed because they have the same ListSelectionModel.
The way you do it is wrong. With your constructor new JList(j) there is only a "read- only model". http://docs.oracle.com/javase/7/docs/api/javax/swing/JList.html It's easy to display an array or Vector of objects, using the JList constructor that automatically builds a read-only ListModel instance for you: You should use a real Model for...
I would suggest your problem(s) start with: Creating a JScrollPane within the addFilesToList method: scrollPane = new JScrollPane(list);. Create the JList AND JScrollPane ONCE, there should be no need to continuously recreate these Use of null layouts. This has been suggested to you more times then I care to remember....
java,swing,jframe,jscrollpane,jlist
Changing a variable's value does not affect a component's state in any way; you must call a component method. Until you do that, your frame has no way of knowing that you created a new JScrollPane. Actually, you should not create a new JScrollPane or a new JList. Instead, you...
There are 2 major problems with that code: In the while loop, you are creating many instances of DefaultListModel. That means, for each entry of the query result, you are restarting the list. A nullpointer exception is produced by the line: connect.rs.next() because you didn't assign connect.rs with the query's...
java,swing,jlist,listcellrenderer
In your implementation of ListCellRenderer you're relying on the getGraphics() of the label. Sometimes, getGraphics() is null which is OK, but you're not entering the if(this.getGraphics() != null) condition and simply returning the unmodified string. That is why you get inconsistent results. Commenting out this condition solved the problem in...
Since you are using a selection mode of MULTIPLE_INTERVAL_SELECTION you have to account for all selections. Consider using a method like this to calculate the total. public int calculateTotalPrice() { int[] selections = otherPrdctList.getSelectedIndices(); int total = 0; for (int i : selections) { total += miscellaneousProdPri[i]; } return total;...
You should be able to change this by using the UIManager: UIManager.put("List.timeFactor", new Long(2000)); The default in the BasicListUI if there is no List.timeFactor default is 1000. Properties of the UIManager should be set before you create your components....
Why not to use some ListModel eg. (http://docs.oracle.com/javase/7/docs/api/javax/swing/DefaultListModel.html) class to manipulate JList?
To start with, you might like to use a single layout manager... setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.gridx = 0; gc.gridy = 0; gc.weighty = 1; gc.fill = GridBagConstraints.BOTH; gc.gridheight = GridBagConstraints.REMAINDER; add(listScroller, gc); gc.gridx = 2; gc.gridy = 0; gc.weighty = 0; gc.fill = GridBagConstraints.NONE; gc.gridheight =...
java,swing,actionlistener,jlist,thread-sleep
Right now only data you can read from list is name and surname, you can achieve by using ListSelectionListener: list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { text.setText(list.getSelectedValue().toString()); } }); ...
java,swing,actionlistener,jlist
You should be using a ListModel when dealing with the JList, for example, an easily manageable DefaultListModel. You can then use the method DefaultListModel.addElement for dynamic population of the list. You first need to initialize your list with the model final DefaultListModel model = new DefaultListModel(); JList jList = new...
With the add(Component) method you try to add a new (graphical) component. This method is usefull if you have a JPanel. But you want to add a new list element to your JList. You have to understand how to work with models in Swing. They represent the data of your...
You have two different JLists. First one where you set ListCellRenderrer. list.setCellRenderer(renderer); and another one you display in dialog: pane.showMessageDialog(null, jlist, "adsfasdf", JOptionPane.PLAIN_MESSAGE); Add: final JList jlist = new JList(d); jlist.setCellRenderer(renderer); to get it working....
First check for selection before getting the value from the JList. Try with JList#getSelectedIndex() that returns -1 if there is no selection instead of JList#getSelectedValue() that returns null if there is no selection. If there is no selection then below line will result in NullPointerException String seleccion =jList1.getSelectedValue().toString(); Read more...
Use setEnabled(boolean enabled) inherited by JLIst from JComponent to enable / disable it like this: yourJlistObject.setEnabled(false); From JComponent JavaDocs: public void setEnabled(boolean enabled) Sets whether or not this component is enabled. A component that is enabled may respond to user input, while a component that is not enabled cannot respond...
java,user-interface,jscrollpane,jlist
This is NOT the suggestion I gave you in your last posting: http://docs.oracle.com/javase/tutorial/uiswing/events/documentlistener.html The JScrollPane containing the JList should be added to your GUI from the start using your desired layout. Then you just change the data in the JList by using the setModel(...) method....
Use setModel to set the model for the JList component jAddList.setModel(listModel); A single model can be set at startup to be manipulated later JList<Integer> jAddList = new JList<>(listModel); ...
You're going to need a custom renderer. You can either use a DefualtListCellRenderer which uses a JLabel as the rendering component, or you can create a custom ListCellRenderer where you can specify the rendering the component by extending the component and impelenting ListCellRenderer. You can see more Providing a Custom...
java,swing,jlist,click-counting
OK, after some Goggling and my own enhancement, here is the code that works to my original expectations : boolean isAlreadyOneClick=false; ... DefaultListModel xlistModel=new DefaultListModel(); JList xlist=new JList(xlistModel); xlist.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int index=xlist.locationToIndex(e.getPoint()); String item=xlistModel.getElementAt(index).toString(); if (SwingUtilities.isLeftMouseButton(e)) { if (isAlreadyOneClick) { System.out.println("Left double click :...
java,swing,jlist,defaultlistmodel
This: void handler(String Name) { ... Should be handler(String Name) { ... To be a constructor, instead of a method. Also, you create a handler with two different parameter lists: empty, and the string. You need a constructor for both. By the way, the code would be a lot easier...
java,swing,jcombobox,jtextarea,jlist
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. Some hints: Create a Manufacturer POJO class that holds the manufacturer's data and a list with its associated cars. Add...
java,swing,jtable,jcombobox,jlist
Unless the values for the JComboBox are dynamically generated for each row, you should be able to just prepare the CellEditor ahead of time, for example... JComboBox cb = new JComboBox(new String[]{"1", "2", "3", "4"}); DefaultCellEditor editor = new DefaultCellEditor(cb); JTable table = new JTable(new DefaultTableModel(5, 1)); table.getColumnModel().getColumn(0).setCellEditor(editor); This will...
int selectedIndex = customerList.getSelectedIndex(); I doubt you want to get the selectedIndex(). I would think you want to get the selected value: String fileName = customerList.getSelectedValue().toString(); File customer = new File("Customers/" + fileName); ...
java,swing,jscrollpane,layout-manager,jlist
It seems that the method: setVisibleRowCount(int) can't be used for JLists which are added to a JPanel which has set a Layoutmanager. I rebuild your application a bit, since I couldn't get it working by using a SpringLayout (I admit, I never used it before). But with the BorderLayout it...
As always, the answer is "it depends." The level of detail is not dictated by the type of diagram, but the context in which the diagram is used. If the diagram is intended to show the flow through a use case, it should probably restrict itself to showing the activities...
java,string,swing,jlist,defaultlistmodel
Make sure you are using a DefaultListModel. /* Create model */ DefaultListModel<String> dlm = new DefaultListModel<>(); /* Add elements */ dlm.addElement("test"); dlm.addElement("test2"); /* JList to use the model */ JList<String> list = new JList<>(dlm); /* Update an element */ dlm.set(1, "test3"); ...
java,swing,mouseevent,jlist,listcellrenderer
Once they are selected (by clicking them, this code is within a click event) I call the ListCellRenderer to change the color of the text No, that's not how it should work, the ListCellRenderer will be called again (by the JList) and the isSelected parameter will be true, to...
java,swing,user-interface,border,jlist
You can achive that with help of ListCellRenderer. Here is simple example: import java.awt.Color; import java.awt.Component; import javax.swing.BorderFactory; import javax.swing.DefaultListCellRenderer; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.ListCellRenderer; public class TestFrame extends JFrame{ public TestFrame(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); init(); pack(); setVisible(true); } private void init() { JList<String> list = new JList<>(new...
java,mysql,csv,resultset,jlist
A few issues with this code. The reason you're only getting the last result is because of this line: fWriter = new FileWriter("Exports/Transfers/" + /* frmNm.replace(":", "_") */"EBW_" + GtDates.fdate + ".csv", false); This line is inside your loop. The false as the last parameter tells FileWriter not to append....
java,swing,jlist,defaultlistmodel,listcellrenderer
getElementAt is returning the Object at the specified position, which happens to be a Student in your case. System.out.println is using the object's toString method to print the object, so, based on your code, it seems to be working. But, if you want the output of "Name: Paul0 Age: 0.",...
In your problem number 2.. also trim your input. you can condition your input like this: String entry = JOptionPane.showInputDialog(null, "Enter part number"); if(entry == null){ // if the user press cancel; return; } entry = entry.trim(); if(entry.equals("") || entry.isEmpty()){ JOptionPane.showMessageDialog(null,"Please enter a valid input!"); return; }else{ entry = "\n"...
java,multithreading,swing,jscrollpane,jlist
It looks like you're blocking the UI thread in the loop - when you call accept(), that's going to wait for a new connection, which means the UI thread can't repaint the UI. You should do that in a separate thread. All UI interactions should be performed in the UI...
java,indexing,jlist,defaultlistmodel
This is the solution that @DanTemple gave me and it worked! 1) Retrieve the data from the model. 2) Clear the data from the model. 3) Rearrange the data as desired. 4) Add the data back into the model....
java,swing,jpanel,jscrollpane,jlist
panel_1.add(list); JScrollPane scrollPane = new JScrollPane(); panel_1.add(scrollPane); Should better be: //panel_1.add(list); JScrollPane scrollPane = new JScrollPane(list); panel_1.add(scrollPane); ...
java,swing,user-interface,jlist
I have checked your above example and found two things. One that it doesn't preserve the previously selected item in the list once we click on Add button to add items to right list. Second thing was that you are using the String to show items in the list but...
Your read method is all over the place... You're constantly reading into an pre-existing array, but you never remove anything from it...so it contains old data... It's dangerous to read into an array without knowing how many lines you actually need... You don't close your resources... Instead, read each element...
java,swing,jtable,jlist,jcheckbox
A basic idea would be to reset the data in the table/model back to false, for example.. for (int row = 0; row < table.getRowCount(); row++) { if (table.getValueAt(row, 4) == Boolean.TRUE) { table.setValueAt(Boolean.FALSE, row, 4); } } Take a closer look at How to Use Tables for more details...
java,swing,user-interface,jlist
You are outputting just the selected value because that's the method you are calling, getSelectedValue(). To display ALL the values, you have to get the model and iterate through the values, like so: int size = CruiseList.getModel().getSize(); StringBuilder allCruises = new StringBuilder("All cruises:"); for(int i = 0; i < size;...
java,user-interface,arraylist,jlist,arrays
To modify the contents of a JList, you need to create your own DefaultListModel. Then, you can construct the JList using the constructor JList(DefaultListModel). JLists can use any object. They will call toString() to get the string to display for each object. Say that the user wants to remove the...
Your question is kind of out of context, as I have no idea how you are refreshing your view, for example. But instead of a JList, I might be temptered to use a JTable, as it's editable and has in built rendering for things like JCheckBox But, first, I would...
There are two ways but both are similar: Way 1: Suppose your JList is jList1 now to use DefaultListModel in your jList1 you need to set jList1 model, follow the code to set model and add values in your jList1: jList1.setModel(new DefaultListModel()); DefaultListModel lm1=(DefaultListModel) jList1.getModel(); lm1.add(0, "A"); lm1.add(1, "B"); lm1.add(2,...
java,swing,jlist,imageicon,defaultlistmodel
I agree with trashgod (+1 to his suggestion), a JTable will be a simpler solution, here's why... JList doesn't support editability, so you'd need to create it... So, first, we'd need some kind of ListModel that provided some additional functionality, in particular, the ability to set the value at a...
I believe you want JList#locationToIndex Modified example from JavaDocs public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { int index = list.locationToIndex(e.getPoint()); System.out.println("Item " + index); } } ...
Why not use s.trim() instead of your removeSpaces method? } else if (src == create) { //show an input dialog box String s = JOptionPane.showInputDialog(this, "What do you want to remember?"); /*f the length of the given string is zero, or if the length of the string without spaces is...
ListModel is a generic type, but you are using it as a raw type. PerhapsListModel<String> = new DefaultComboxBoxModel<String>(new String[] {""})...
Well use DefaultListModel and its addElement() method in your while loop to add each result, like the following: listModel = new DefaultListModel(); while (rs.next()) { String vorname = rs.getString("Vorname"); String nachname = rs.getString("Nachname"); listModel.addElement(vorname + " " + nachname); System.out.println(vorname + " " + nachname); } //then create a list...