jlist

Adding an ActionListener to a JList

帅比萌擦擦* 提交于 2019-12-19 18:28:03
问题 I have a JList with an array of strings. Basically it displays a restaurant menu. right next to the JList i have another JList which is empty. Whenever a user double clicks on a string in the first JList (where the menu is displayed) I want it to show up on the next JList which is right next to it. how do i do that? 回答1: You can try final JList list = new JList(dataModel); MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) {

Adding an ActionListener to a JList

风格不统一 提交于 2019-12-19 18:27:32
问题 I have a JList with an array of strings. Basically it displays a restaurant menu. right next to the JList i have another JList which is empty. Whenever a user double clicks on a string in the first JList (where the menu is displayed) I want it to show up on the next JList which is right next to it. how do i do that? 回答1: You can try final JList list = new JList(dataModel); MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) {

JList and ArrayList update

十年热恋 提交于 2019-12-19 11:36:31
问题 I would like to have example on how to update a JList when I add or remove elements from a ArrayList. The ArrayList is part of Model class. The Model class is passed to the view (which is a JPanel containing several swing components, and the JList I want to update) via its constructor. The model class is also injected in a class that reads values received from the server. When i received data from the server I add some of them to my arrayList by doing model.getArrayList().add(data). When I

JList text alignment

怎甘沉沦 提交于 2019-12-19 07:36:52
问题 I have a JList with items that I want to show two values. Is there a way to have it show a string name and then have a right justified string to show a value. Looking something like this: Title__________________120 Title2_________________135 Is it possible to pass in two string to an item and have the first string display on the left and the second one on the right? 回答1: Sure, implement a custom renderer. You might return a JPanel with BorderLayout as the rendering component, with the LHS

Synchronized JList and JComboBox?

耗尽温柔 提交于 2019-12-19 06:29:28
问题 In Java Swing, what's the best way for a JList and a JComboBox to be synchronized in terms of the data, i.e., to have the same list of items at any given point of time? Basically, if I add items to (or remove items from) one, the other should reflect the change automatically. I've tried doing the following, but it doesn't seem to work: JList list = new JList(); JComboBox comboBox = new JComboBox(); DefaultListModel listModel = new DefaultListModel(); // add items to listModel... list.setModel

Synchronized JList and JComboBox?

假装没事ソ 提交于 2019-12-19 06:29:07
问题 In Java Swing, what's the best way for a JList and a JComboBox to be synchronized in terms of the data, i.e., to have the same list of items at any given point of time? Basically, if I add items to (or remove items from) one, the other should reflect the change automatically. I've tried doing the following, but it doesn't seem to work: JList list = new JList(); JComboBox comboBox = new JComboBox(); DefaultListModel listModel = new DefaultListModel(); // add items to listModel... list.setModel

Add a Jlist to a JScrollPane

拟墨画扇 提交于 2019-12-19 04:18:29
问题 I have a JList that I need to Place inside a scroll Pane because I am getting the JList from the database and the values can increase greatly. I need to be able to scroll them down so I wrote: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; public class Checkboxlistener extends

Adding elements to JList in Swing Java

ぐ巨炮叔叔 提交于 2019-12-18 20:49:44
问题 I have a function that executes when a button is clicked. Suppose there is a loop to add 1 to 10 to a JList . I add that data to DefaultListModel . It works perfectly and the numbers get added. Then I added a Thread.sleep(1000) within the loop. But the output is different. I wanted to add 1 element every second. But now it waits for 10secs and the add all 1 to 10 together at the end of 10th second. Am I wrong anywhere? List processList = listNumbers.getSelectedValuesList(); DefaultListModel

How do you change border of the pop up section of a JComboBox?

别说谁变了你拦得住时间么 提交于 2019-12-18 09:21:50
问题 I wan't to change the border of the popup/selection part of the JComboBox. Note that the UI is BasicComboBoxUI I've tried: weaponCB.setRenderer(new DefaultListCellRenderer() { @Override public void paint(Graphics g) { setBorder(whiteBorder) //whiteBorder is a white border super.paint(g); } }); but it gave me this: and: for (int i=0; i<weaponCB.getComponentCount(); i++) { if (weaponCB.getComponent(i) instanceof AbstractButton) { ((AbstractButton)weaponCB.getComponent(i)).setBorder(whiteBorder)

Can Items in a JList be formatted as HTML

孤街浪徒 提交于 2019-12-18 08:14:08
问题 I would like to create a JList in Java so that each individual item is formattted using HTML tags, but I'm not clear how to do this or even if this is possible. Does anyone have any suggestions? Thank you. 回答1: Its actually very simple. For every string in the list surround it with the html tags such as this: <html><font color=green>this will be green</font></html> When the JList displays it it will be green. 回答2: Swing supports the use of HTML in many of the controls that display text. In