jlist

How do i add an action listener to a JList in a proper way?

我的未来我决定 提交于 2019-12-13 07:25:05
问题 I'm trying to add an actionListener to a JList, so whenever a user click a value in the JList , it will just println the value. Here's the code public class FontProgram { public static void main(String[] args) { // TODO Auto-generated method stub JFrame mainFrame = new JFrame("Fonts Frame"); JPanel panel = new JPanel(new BorderLayout()); GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames = e.getAvailableFontFamilyNames(); JComboBox fontbox = new

Jlist is not getting updated when an action performed by selecting an item in Combobox

房东的猫 提交于 2019-12-13 05:25:15
问题 I am trying to perform action by selecting a value in Combobox and after selection, based of the value selected Jlist should be updated. But list is taking value only first time but its not getting updated while changing the values. However Values are coming and action is performed as I can see values are coming in consol.My code is as follows: ArrayList< String> ModuleNames = GetModuleNames(); String[] ModuleNames1 = ModuleNames.toArray(new String[ModuleNames.size()]); comboModuleName = new

java chat sending users list from server to clients and update it

旧街凉风 提交于 2019-12-13 05:15:55
问题 I write client-server chat using sockets. Help me please understand how send the list of current registered users from server to clients and update it when list changed. I read this similar post but steel don't understand how to do it. I used BufferedReader and PrintWriter streams for sending and receiving messages. And I don't want sending the list of the users any time when clients send messages. I keep list of users in a map as a key set on the server side. public class Server{ private

DefaultListModel modify jList view

大城市里の小女人 提交于 2019-12-13 04:29:12
问题 If I have the following scenario DefaultListModel model = new DefaultListModel(); model.addElement(file1.getName); model.addElement(file2.getName); ... //Add to list myJList.setModel(model); Now the list would obviously display the file name which is what I want. However if I were to process the files I would then need the actual path. So how would I achieve this outcome where the JList displays only the name but at the same time the model has stored the full path ? Alternately I could of

Drag and Drop in Java - Painting more than just a border

风流意气都作罢 提交于 2019-12-13 04:17:50
问题 I have a JTable and a JList and I have my code set up so that I can drag from the JTable to the JList using built in Swing methods. When I drag from the JTable to the JList, the "image" that is dragged is simply a border of the thing I am dragging. Specifically, in the case of the source being a JTable, the image is just a border of the row I selected to drag. How can I override what this "image" is? How can I get it so that the user can drag text, not just a border (rectangle)? 回答1: You

JList with Image and text: Where text is coming from an ArrayList<String>

对着背影说爱祢 提交于 2019-12-13 00:56:37
问题 i have a simple example of a JList that is getting it's data from an ArrayList but i want to show an image next to each string in the list. I have written a custom cell renderer (IconListRenderer) that is suppose to display an icon and the object side-to-side. Here is a running sample. //Test class showing the list in a frame import java.awt.Color; import java.awt.Dimension; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import javax.swing.*; import javax.swing

Deleting Selected Checkbox using java swings without using Jtable/Database

这一生的挚爱 提交于 2019-12-12 21:55:12
问题 I am new to swings, trying to delete selected checkbox on click of delete button in java swings, i tried by using "DefaultListModel" ,here i able to delete normal data not with check box here my code: import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.BorderFactory; import

Drag and Drop in JList is not working

耗尽温柔 提交于 2019-12-12 19:21:57
问题 So I have written a TransferHandler for my application (along the example from Oracle site) but when I am trying to move the data it is not moving. All it is doing is copying the data at index ( n-1 i.e if I am moving and item to n location) to index n. Could you please check what is wrong, though I have tried many options but none of them is working for me. import javax.swing.TransferHandler; import javax.swing.*; import java.awt.datatransfer.*; public class ListTransferHandler extends

type JList does not take parameter type <String>

别等时光非礼了梦想. 提交于 2019-12-12 16:07:32
问题 When I try to compile some code I keep getting these errors: CCC.java:21: type javax.swing.JList does not take parameters JList<String> list; or: CCC.java:30: type javax.swing.DefaultListModel does not take parameters DefaultListModel<String> jobs, DefaultListModel<String> closJ) throws HeadlessException { I have about 26 of the same error when I try to remove the section i get about 150 lines of errors can anyone help please. 回答1: Generics were added to JList in Java 7. Here's an example

Efficiency of JList Search

此生再无相见时 提交于 2019-12-12 14:25:55
问题 I came across some java code for doing a prefix search on a JList. Looking at it however, the meat of the algorithm is quite inefficient, using a linear search over the list for each keypress, and doing a slow case conversion within the tight loop. I would imagine for very large amounts of data, a custom-implemented ternary search tree would be a much more efficient solution. However, if one was striving for simple code and did not have the performance requirements necessitating such