jlist

JList with tooltip text in DafaultListModel

て烟熏妆下的殇ゞ 提交于 2019-12-08 13:35:00
问题 I have a JList and each item of the JList has a distinct display text and tooltip text. I would like to use 'DefaultListModel' for the JList. My question is that is it possible to somehow save the tooltip text when added an item to the DefaultListModel. Thanks. 回答1: You can override the getToolTipText(...) method to provide your custom tool tip. For example: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ListToolTip extends JFrame { public ListToolTip() {

Problems updating my JList for active channels

China☆狼群 提交于 2019-12-08 11:35:39
问题 Intro: I've created a chatprogram where a client connects the server. The client is able to join channels, and when they do, the jList(see code) should be updated via DefaultListModel with (getChannel()), and should show all other clients connected to the same channel. I know the getChannel(); works, since ive debugged it(and use systemoutprint). I already have Jlists for active channels and usersonline, which works! :) The clients use callback methods to notify the other clients connected to

Applying a ListCellRenderer to individual cells on a JList

不打扰是莪最后的温柔 提交于 2019-12-08 11:01:45
问题 Is it possible to apply a listcellrenderer to purely one cell in a jlist ? My code currently works fine in applying the renderer, but I would like to set a different dynamic variable for each entry. Apologies if this is a little vague.. So to sum up - I want to apply listcellrenderer to only one cell in a list, how would I do this? 回答1: Is it possible to apply a listcellrenderer to purely one cell in a jlist? No, all cells would have to share the same renderer. That's how renderers work. My

Adding items to an already existing jlist from another class

删除回忆录丶 提交于 2019-12-08 09:11:29
I have a jList (named JList1) created using the Desing mode from NetBeans IDE, and I want to add items to that list using a secondary class which parses a big xml list and gets the data from it. My problem is that I dont really understand how to do this, I already tried a lot of different codes, tried with a model too, but cant get it right. I am new to java (and programming too), and I dont understand if I do something like String[] ar = {"one", "two", "three"}; JList Jlist1 = new JList(ar); this created a new jList instead of using my already created one, no ? created using the Desing mode

JList: sorting by Up/down buttons

白昼怎懂夜的黑 提交于 2019-12-08 08:04:34
问题 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

Select item in list, show text in text area

北城以北 提交于 2019-12-08 07:20:34
问题 I am working on a rough draft of a gui, looking at different options. I was hopping to use a JList to show text in a JTextArea based on what item is selected. You can see the JList on the left and the JTextArea in the center. Or is there a better way to do this? I am already using tabs that will be used for a broad category. I saw that the CardLayout , but don't quite like the look. Any tips? 回答1: Well, you can use a ListSelectionListener to set the content accordingly.. JList list = new

Adding items to an already existing jlist from another class

爷,独闯天下 提交于 2019-12-08 07:12:59
问题 I have a jList (named JList1) created using the Desing mode from NetBeans IDE, and I want to add items to that list using a secondary class which parses a big xml list and gets the data from it. My problem is that I dont really understand how to do this, I already tried a lot of different codes, tried with a model too, but cant get it right. I am new to java (and programming too), and I dont understand if I do something like String[] ar = {"one", "two", "three"}; JList Jlist1 = new JList(ar);

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

蹲街弑〆低调 提交于 2019-12-08 05:44:32
问题 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

How to make the jList selectable inside a jTable

不打扰是莪最后的温柔 提交于 2019-12-08 03:41:52
问题 How to make the jList selectable and jScrollPane scrollable inside a jTable. This is my table code : private JTable getCalendarTable() { if (calendarTable == null) { calendarTable = new JTable() { public boolean isCellEditable(int nRow, int nCol) { if (nRow % 2 != 0) { return true; } else return false; } }; DefaultTableModel mtblCalendar = (DefaultTableModel) calendarTable .getModel(); String[] headers = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; for (int i = 0; i < 7; i++) {

How to set the color of a Font?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 02:41:26
问题 I have a JList and inside that list, I want to change the color of the font of the following words. Someone said that I have to use CellRenderer but I'm not yet familiar with that. Now, my problem is how can I setup this renderer to change the color of the Font? Any idea about this matter? Thanks... 回答1: Check out the JavaDoc, it might just have what you need (the example at the top). Basically you just return a component (like a JLabel) with a configured font color. Edit: since you want to