defaultlistmodel

Using JList with a model?

两盒软妹~` 提交于 2019-12-11 08:08:09
问题 I'm making an application that lets you add files and then compress them but how to get the files from my hard drive or any hard drive for that matter into my application? I can get the file through a filereader but how to put it into my GUI? I read that defaultListModel is the way to go but am unsure. public class LockNCompressWindow { public static void main(String[] args) { LockFrame w = new LockFrame(); w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); w.setSize(500,500); w.setResizable

Java Swing, Corba Objects - How to store Corba objects in DefaultListModel?

不羁岁月 提交于 2019-12-11 05:40:36
问题 I have such IDL interface: interface User { string toString(); //.. }; interface Group { typedef sequence<User> Users; Users getUsers(); }; When I translated it to C++ I got sth like this: // ... Group::Users* GroupImpl::getUsers() { // ..return sequence of 'User'-objects } On client side (written in Java) I want to show my users. I do sth like this: public void showAllUsers() { User[] users = interface_obj.getUsers(); if(users.length != 0) { DefaultListModel model = new DefaultListModel();

JList not responding to listModel.addElement(

依然范特西╮ 提交于 2019-12-11 02:35:57
问题 I have a JList in my Java Swing application and when a user clicks a button, the list clears and the contents reset as follows: public void reset(ArrayList<String> content) { listModel.removeAllElements(); System.out.println(content.size()); for(int i = 0; i < content.size(); i++) { listModel.addElement(content.get(i)); System.out.println("Added element " + content.get(i)); } } The list is initialized as follows listModel = new DefaultListModel(); list = new JList(listModel); However there is

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() {

Display a property of Objects in Jlist

只谈情不闲聊 提交于 2019-12-05 08:08:10
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 load the objects in the list model, but then the JList displays the address of those. Is there an

Java - Updating JList after changing an object

断了今生、忘了曾经 提交于 2019-12-04 03:15:10
问题 I have a JList which uses a DefaultListModel. I then add values to the model which then appear in the JList. I have created a MouseListener which (when double clicked) allows the user to edit the current user number of that person they have selected. I have checked that the actual object of that record is being changed, and it is. The only issue I'm having is getting the actual Jlist to update to show the new values of that object. Snippets of the current code I have are: Creating the JList

Removing items from JList

穿精又带淫゛_ 提交于 2019-12-03 21:51:11
问题 I've got a simple Jlist with data from List<String> , Now I want to remove selected item from Jlist. Here is the code: final DefaultListModel<String> model = new DefaultListModel(); final JList list = new JList(model); //filling list //loop for every element from List<String> public static void sample(DefaultListModel model, List<String> data) for(int i=;i<data.size();i++) {model.addElement(data.get(i));} //btn pressed public void actionPerformed(ActionEvent arg0) { int index = list

HashMap into DefaultListModel

◇◆丶佛笑我妖孽 提交于 2019-12-02 09:30:24
Here's the code that I have: HashMap<String, String> inst1 = new HashMap(instructorIO.getInstructors()); instListModel = new DefaultListModel<String>(inst1.values()); I get errors: DepartmentProject.java:69: error: constructor DefaultListModel in class DefaultListModel<E> cannot be applied to given types; required: no arguments found: Collection<String> reason: actual and formal argument lists differ in length where E is a type-variable: E extends Object declared in class DefaultListModel Can anyone help me with this? DefaultListModel only has a constructor that takes no arguments; you can't

JList not updating when adding element to DefaultListModel

自古美人都是妖i 提交于 2019-12-02 05:54:11
I'm trying to create a simple program to manage Employees. When trying to add a new employee I can't seem to get the employee to be displayed on the Jlist. The main frame... public class EmployeeFrame extends JFrame implements ActionListener { // The buttons to display private JButton addButton; private JButton editButton; private JButton deleteButton; private JButton saveButton; // The underlying list of employees, and the GUI object to display them private DefaultListModel<Employee> listModel; private JList<Employee> employeeList; public static final String SAVE_FILE = "employees.txt"; /** *

Java - Updating JList after changing an object

耗尽温柔 提交于 2019-12-01 16:28:41
I have a JList which uses a DefaultListModel. I then add values to the model which then appear in the JList. I have created a MouseListener which (when double clicked) allows the user to edit the current user number of that person they have selected. I have checked that the actual object of that record is being changed, and it is. The only issue I'm having is getting the actual Jlist to update to show the new values of that object. Snippets of the current code I have are: Creating the JList and DefaultTableModel: m = new DefaultListModel(); m.addListDataListener(this); jl = new JList(m); jl