jlist

how to create jcombobox with jcheck box and multiple selection

被刻印的时光 ゝ 提交于 2019-12-08 00:33:19
问题 I want to create JComboBox with checkboxes and multiple selection . i have created a list with check box after rendering the jlist . I dont know how to render it with jcombobox . Or is it possible to make jlist as drop down list like combo box . for jlist rendering i am using the following code DefaultListModel listModel = new DefaultListModel(); ListCheckBox li= new ListCheckBox(listModel); JScrollPane jsp= new JScrollPane(li); add(jsp); listModel.add(0,new JCheckBox("Other Court"));

How to start a Timer on a mouse exit event and stop that same Timer on a mouse enter event?

和自甴很熟 提交于 2019-12-07 03:31:30
I have a list called reminderList . When the mouse clicks on an item in the list and the mouse exits the list, i want a timer to start. When the mouse enters the list, i want that timer to stop, if it is still running. When the mouse exits the list again, i want that same timer to restart. public void waitReminderList(int status) { Timer timer = new Timer(10000, new ActionListener() { public void actionPerformed(ActionEvent evt) { reminderList.clearSelection(); dismissReminder.setEnabled(false); } }); if (status == 0) { if (!reminderList.isSelectionEmpty()) { timer.setRepeats(false); timer

Change JList item background color on hover

时光总嘲笑我的痴心妄想 提交于 2019-12-07 02:33:24
I'm trying to change the background color of a JList cell when it is being hovered over, but I'm not sure how to do it. Here is what I currently have: package cats.youtube.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.util.LinkedList; import javax.swing.AbstractListModel; import javax.swing.DefaultListCellRenderer; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax

JList: sorting by Up/down buttons

↘锁芯ラ 提交于 2019-12-06 14:50:58
Question: Is there an easy way to sort jList using Up/Down Buttons on jFrame? My JList stores path's of image files and displays string with name of the file. I would like to move down/up the element by clicking down/up Button. Here's what I did - the effect is moving the selection (blue field), not the element. Button2 is button "up". private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { int indexOfSelected = jList1.getSelectedIndex(); File selectedFile = (File) jList1.getSelectedValue(); indexOfSelected = indexOfSelected - 1; jList1.setSelectedIndex(indexOfSelected ); jList1

JButton not Responding to Click Events

余生长醉 提交于 2019-12-06 12:49:29
问题 An application i am working on requires the use of a JList where each ListItem is a Label followed by a Button. What i did is i created a Class having a String member for the Text field and added the Class Objects to the Jlist. Now for the Button,i implemented a Custom List Cell Renderer which is as : public renderer() { text=new JLabel(); button=new JButton("Track"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto

Java GUI Swing Jlist with three Components

两盒软妹~` 提交于 2019-12-06 10:59:15
I need to create a Java Swing JList with three Components. Each JList row should have one JCheckBox, one ImageIcon and one JLabel. The problem is that JLabel could have only two elements. So i need a methode to add a JCheckBox... Jlist with three components:- Without any real information, the best I can suggest is start by having a look at Concepts: Editors and Renderers and Writing a Custom Cell Renderer for how cell renders work. Based on you basic requirements, you need to start with a container class of some sort and add your components to it, you then need to populate the values of the

Filtering JList based on JTextField

烈酒焚心 提交于 2019-12-05 23:56:32
问题 I have a JTextField and a JList in my program. The JList contains the user's contacts. I'd like to filter the JList based on the text on the JTextField. For example, if I type in "Mike" it will only show contacts including "Mike". When the user clears the JTextField it would reset the filter. I know I could do this manually by having two arrays. One for the original contacts and one for the filtered ones. When the user changes the value of the JTextField I would go trought the original list,

JOptionPane and scroll function

て烟熏妆下的殇ゞ 提交于 2019-12-05 20:15:13
问题 I want to JList a lot of results in a JOptionPane, however, I'm not sure how to add in a scroll function should there be too many results. How would I add a scroll bar to a JOptionPane? Any help would be great. Thanks. 回答1: Here is an example using a JTextArea embedded in a JScrollPane : JTextArea textArea = new JTextArea("Insert your Text here"); JScrollPane scrollPane = new JScrollPane(textArea); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); scrollPane.setPreferredSize( new

Trouble with JCheckBox checked toggle logic in a JList in Java

我怕爱的太早我们不能终老 提交于 2019-12-05 19:01:42
Hi I am having trouble with toggling a check box that is in a JList, I wish for when an item is clicked to have the check box tick, and if it is ticked again i want it to toggle to unticked. I want to have it possible to have multiple items to be ticked or unticked without the use of the ctrl or shift keys. public class CustCellRenderer extends JCheckBox implements ListCellRenderer { boolean selected = false; void CustCellRenderer() { setOpaque(true); setIconTextGap(12); } // allows a custom list cell rendering which will enable me to display an icon as well as filename @Override public

Display a property of Objects in Jlist

只谈情不闲聊 提交于 2019-12-05 08:08:10
I have a Ingredient class public class Ingredient { String NameP; List ListS; String Desc; List ListT; ... multiple instances of this class are stored in a Objects list. I have also a javax.swing.JList ListIng; With it's model set to ListIngModel = new DefaultListModel(); The idea is to use the Jlist to display the field "NameP" of all objects, select one of them to be further inspected and then grab the selected object: Ingredient Selected = ListIngModel.get(ListIng.getSelectedIndex()) I can load the objects in the list model, but then the JList displays the address of those. Is there an