jlist

How can we make a list editable?

╄→гoц情女王★ 提交于 2020-07-09 13:29:21
问题 I want to make my JList editable, what should I do? 回答1: Use a 1-column JTable instead. 回答2: List Editor 回答3: You can find the source code for an editable list here: http://www.java2s.com/Code/Java/Swing-Components/EditableListExample.htm Depending on your use case an JComboBox , which is editable, might be a better solution than a JList . 来源: https://stackoverflow.com/questions/1788552/how-can-we-make-a-list-editable

Making button in JList clickable

岁酱吖の 提交于 2020-07-03 06:09:29
问题 I can't believe this does not work. I have a JList. I have set its renderer as follows. Basically RankingPanel is a JPanel with two labels and a button. topAchieverList = new JList(); topAchieverList.setCellRenderer(new TopBottomCellRenderer()); Here is my TopBottomCellRenderer. class TopBottomCellRenderer extends RankingPanel implements ListCellRenderer { public TopBottomCellRenderer() { } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,

Force JList to NOT wrap at all?

╄→гoц情女王★ 提交于 2020-04-14 13:11:31
问题 Is there a possibility to force JLists to display all items on one line? setOrientationLayout() does not give you that option. 回答1: list.setLayoutOrientation(JList.HORIZONTAL_WRAP); list.setVisibleRowCount(1); 来源: https://stackoverflow.com/questions/7144689/force-jlist-to-not-wrap-at-all

Force JList to NOT wrap at all?

我是研究僧i 提交于 2020-04-14 13:07:30
问题 Is there a possibility to force JLists to display all items on one line? setOrientationLayout() does not give you that option. 回答1: list.setLayoutOrientation(JList.HORIZONTAL_WRAP); list.setVisibleRowCount(1); 来源: https://stackoverflow.com/questions/7144689/force-jlist-to-not-wrap-at-all

How would I code when a item has been selected in a JList?

≯℡__Kan透↙ 提交于 2020-02-03 14:13:48
问题 I have a JList with 5 options in it and when one of the items becomes selected or clicked i want the text area next to it to show a paragraph of text relative to the item clicked. It should do this for each item in the list but I cant seem to find how to do it in the API How would my program know if an item in the JList was selected so I can work with the data? 回答1: Use addListSelectionListener. You can create a subclass (anonymous or not) of ListSelectionListener that does the work you want.

How would I code when a item has been selected in a JList?

为君一笑 提交于 2020-02-03 14:06:39
问题 I have a JList with 5 options in it and when one of the items becomes selected or clicked i want the text area next to it to show a paragraph of text relative to the item clicked. It should do this for each item in the list but I cant seem to find how to do it in the API How would my program know if an item in the JList was selected so I can work with the data? 回答1: Use addListSelectionListener. You can create a subclass (anonymous or not) of ListSelectionListener that does the work you want.

How to specify Jlist width?

无人久伴 提交于 2020-02-01 09:12:06
问题 I want to specify fixed width of my JList I followed example provided by Gilbert Le Blanc 22k getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); Panel panel = new JPanel(); panel.setBackground(Color.WHITE); getContentPane().add(panel); String [] queries = {"a", "b", "a", "b" , "a", "b", "a", "b"}; panel.setLayout(new BorderLayout()); JList list = new JList(queries); list.setMaximumSize(new Dimension(200, 200)); // this line does not do the job list.setMinimumSize

How to specify Jlist width?

*爱你&永不变心* 提交于 2020-02-01 09:12:06
问题 I want to specify fixed width of my JList I followed example provided by Gilbert Le Blanc 22k getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); Panel panel = new JPanel(); panel.setBackground(Color.WHITE); getContentPane().add(panel); String [] queries = {"a", "b", "a", "b" , "a", "b", "a", "b"}; panel.setLayout(new BorderLayout()); JList list = new JList(queries); list.setMaximumSize(new Dimension(200, 200)); // this line does not do the job list.setMinimumSize

JList - deselect when clicking an already selected item

瘦欲@ 提交于 2020-01-27 23:49:29
问题 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

Custom deletion Container for Transferable and Transferhandler on JList

戏子无情 提交于 2020-01-25 06:56:05
问题 I tried to fix this issue for the past week but somehow I cant seem to find a solution. There is not a lot of information about this topic so its hard to find examples or code to look at. What I have here is a JList which uses a custom TransferHandler that creates a custom Transferable, for reference here's the code of the involved classes: Transferable: package org.dinhware.swing.special; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt