jlist

Java JList scroll to selected item

你。 提交于 2019-12-03 09:50:30
I have a JList with a lot of items in it, of which one is selected. I would like to scroll to the selected item in this JList , so the user can quickly see which item is selected. How can I do this? String[] data = {"one", "two", "three", "four", /* AND A LOT MORE */}; JList dataList = new JList(data); JScrollPane scrollPane = new JScrollPane(dataList); This should do it: dataList.ensureIndexIsVisible(dataList.getSelectedIndex()); Or, if multi-selection is enabled : dataList.scrollRectToVisible( dataList.getCellBounds( dataList.getMinSelectionIndex(), dataList.getMaxSelectionIndex() ) ); You

How to set the ListModel of a JList in Netbeans?

雨燕双飞 提交于 2019-12-03 03:24:14
I have designed a Swing GUI with the help of Netbeans IDE and this GUI contains a JList. Bydefault, it uses AbstractListModel to pass it as an argument in the JList contructor to create that JList. I want to specify somewhere in the Netbeans to pass DefaultListModel as the model to be passed in that JList so that later I can retrieve it to make changes in the listModel. How can I do that. You have two ways of doing this: 1) In your code manually call list.setModel() anywhere after initComponents() is called. 2) Do it through NetBeans - Right click the list, go to "Customize Code". The first

Add String to JList exactly where they're dropped, not at the bottom

僤鯓⒐⒋嵵緔 提交于 2019-12-02 22:36:28
问题 I've got a couple of JList both being able to be sources and destinations of DnD COPY actions. They work fine, but for one thing - elements are added at the bottom of the lists, instead at the drop destination row, as I'd like. Since Oracle BasicDnD example includes this feature (and, in fact, it's the only application I've been able to find through Google with it), I've been taking a look at its source to see if I was able to adapt it. I tried to set the TransferHandler object, which is what

How to Transfer selected objects from one JList to another JList in swing?

你。 提交于 2019-12-02 19:55:36
问题 I want to transfer the selected objects from one JList to another JList, say List1 and List2. 回答1: Here I am showing you example of transferring name of cities from list to list_1 . You will receive output something like this: Code for this is : import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.DefaultListModel; import java.awt.Font; import javax.swing.JScrollPane; import javax.swing.JButton; import java.awt.event.ActionListener; import java

JList gets updated but just allow users to select items once

瘦欲@ 提交于 2019-12-02 19:14:43
问题 I have a JList that is located in a JScrollPane. The application has a button for users to browse fileSystem and select a category to show its files and folders. First time user clicks on the button JList shows the list and enables user to select from the list but if user clicks on the browse button for the second time new items will be shown but he wont be able to select any item from the list anymore. public class Main { private JFrame frame; final JFileChooser fc = new JFileChooser();

Gui JList ActionListener

前提是你 提交于 2019-12-02 18:06:16
问题 hey all goodevening i have a problem about my second button named "Submit" because i cant transfer all information i entered to my null JList in the frame here is my code so far my problem is if i clicked submit my all information will appear in my Message area in frame it needs to be list. thanks import javax.swing.*; import java.awt.*; import java.awt.event.*; public class vin extends JFrame { JLabel lab = new JLabel("Enter Your Name :"); JLabel lab2 = new JLabel("Enter Your Birthday :");

How to change a cell icon of JList in run time

亡梦爱人 提交于 2019-12-02 15:37:33
问题 How can I change a JLabel icon of only one JList cell(for example: clicking in JList)? I tried to access the JLabel getting with listCellRender but it don't works: @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { ListCellRenderer r = list.getCellRenderer(); JLabel comp = (JLabel) r.getListCellRendererComponent(list, list.getSelectedValue(), list.getSelectedIndex(), false, false); comp.setIcon(UIManager.getIcon("Tree.leafIcon")); } Can anyone give some

Writing something in JList

萝らか妹 提交于 2019-12-02 11:12:18
hey i have another problem. I created JList in my main window and now i want to add something to it. I do it this way... private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { Dodaj_Przedmiot dodaj_przedmiot = new Dodaj_Przedmiot(null, true); dodaj_przedmiot.setVisible(true); SterowanieBazy instance = SterowanieBazy.getInstance(); Zmienne_pomocnicze zp = new Zmienne_pomocnicze(); String przedmiot = zp.getPrzechowaj(); instance.dodajPrzedmiot(przedmiot); String przedm[] = instance.zwrocPrzedmioty(); jList1.setListData(przedm); } what i want to write in that list is what i

How to change a cell icon of JList in run time

戏子无情 提交于 2019-12-02 09:59:07
How can I change a JLabel icon of only one JList cell(for example: clicking in JList)? I tried to access the JLabel getting with listCellRender but it don't works: @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { ListCellRenderer r = list.getCellRenderer(); JLabel comp = (JLabel) r.getListCellRendererComponent(list, list.getSelectedValue(), list.getSelectedIndex(), false, false); comp.setIcon(UIManager.getIcon("Tree.leafIcon")); } Can anyone give some idea? Thanks in advance! My code: import java.awt.*; import java.util.Arrays; import javax.swing.*;

Gui JList ActionListener

♀尐吖头ヾ 提交于 2019-12-02 09:18:26
hey all goodevening i have a problem about my second button named "Submit" because i cant transfer all information i entered to my null JList in the frame here is my code so far my problem is if i clicked submit my all information will appear in my Message area in frame it needs to be list. thanks import javax.swing.*; import java.awt.*; import java.awt.event.*; public class vin extends JFrame { JLabel lab = new JLabel("Enter Your Name :"); JLabel lab2 = new JLabel("Enter Your Birthday :"); JLabel lab3 = new JLabel("Enter Your Age:"); JLabel lab4 = new JLabel("Enter Your HomeTown:"); JLabel