jlist

Populate JTextField when JList item is double clicked

妖精的绣舞 提交于 2019-12-24 05:31:41
问题 I am trying to populate a JTextArea from a JList when the user double clicks the item. I am not completely sure how to accomplish this, here is what I have so far. // Create Top Right JPanel and JList String[] listB = { "Some content on the right panel", "More content", "Some more content", "More and more content", "More and more content", "More and more content", "More and more content", "More and more content", "More and more content", "More and more content", "More and more content", "More

JList not showing on JScrollPane

北战南征 提交于 2019-12-23 22:29:50
问题 I am making a program for a family enterprise that will manage the brochures from their raw materials providers. I find you will need all the code, so I posted it on pastebin. http://pastebin.com/Gc3aLe10 But also, here I attach where I think the problem is: tnBuscar.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { String search = searchField.getText(); Connection con = null; java.sql.Statement st = null; ResultSet rs = null; String url = "jdbc:mysql:/

JScrollBar don't show thumb in Nimbus L&F

早过忘川 提交于 2019-12-23 16:25:43
问题 I got a problem which only happens on Nimbus L&F. If there are too many items in a JList, the thumb of JScrollBar will disappear. But in metal L&F, the thumb will be always visible, because it has a min size. I have also checked the logic in Nimbus L&F, there does have a same min size. But it not effected. Please see my code below: public static void main(String[] args) { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { try {

Using the JList .setModel() method with a class as an argument

蓝咒 提交于 2019-12-23 10:01:12
问题 My ultimate goal is to have a JList which refreshes its content at runtime, and I have found a solution that works from this post here on SO, however I am curious why my original idea did not. As of now, I have something like this setup and it works: DefaultListModel default = new DefaultListModel(); for(int i = 0; i < array.size() ; ++i){ test.addElement(array.get(i)); } list.setModel(default); Below was my original plan. I wanted to have a class which implemented ListModel be passed as an

Trouble with JCheckBox checked toggle logic in a JList in Java

你离开我真会死。 提交于 2019-12-22 11:10:16
问题 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

Adding list item to JList from another JList

删除回忆录丶 提交于 2019-12-22 10:29:16
问题 I have the following code working made_list.setListData(original_list.getSelectedValues()); here made_list is one JList and original_list is another JList. If i run with this code the selected value from original_list is replacing the previous value in made_list. I dont want that. i want to append instead.. How do i do this ?? 回答1: 1) Get the model for made_list 2) Get the selected items from orig_list 3) Make a new object[] that is the size of 1) + 2) 4) populate 3) with the items from 1) +

Display a property of Objects in Jlist

梦想的初衷 提交于 2019-12-22 05:31:50
问题 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

Make JList Values Unselectable [duplicate]

▼魔方 西西 提交于 2019-12-21 09:36:45
问题 This question already has answers here : Disable items in JList (4 answers) Closed 6 years ago . I was wondering how to modify a JList so that clicking any values would not do anything. I have looked at other questions but none have helped. 回答1: I solved it by using the following class: class DisabledItemSelectionModel extends DefaultListSelectionModel { @Override public void setSelectionInterval(int index0, int index1) { super.setSelectionInterval(-1, -1); } } I instantiated the class here:

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

旧巷老猫 提交于 2019-12-21 09:02:27
问题 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 - How do I get a all the selected values from a JList?

…衆ロ難τιáo~ 提交于 2019-12-21 09:02:21
问题 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:/