listcellrenderer

Change JList item background color on hover

时光总嘲笑我的痴心妄想 提交于 2019-12-07 02:33:24
I'm trying to change the background color of a JList cell when it is being hovered over, but I'm not sure how to do it. Here is what I currently have: package cats.youtube.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.util.LinkedList; import javax.swing.AbstractListModel; import javax.swing.DefaultListCellRenderer; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.ListSelectionModel; import javax

Get Value from JComboBox

坚强是说给别人听的谎言 提交于 2019-12-06 11:52:27
问题 I have JComboBox with 2 columns and I have JButton . When I click the JButton , I need to get the result of the JComboBox selected value from first column and seconds column separately... How do I this? Also: how do I set the header of that JComboBox ? The Code: public class Combo extends JFrame implements ActionListener{ private JComboBox combo = new JComboBox(); private JButton button = new JButton(); public Combo() { setLayout(new FlowLayout()); combo.setRenderer(new render()); add(combo);

Trouble with JCheckBox checked toggle logic in a JList in Java

我怕爱的太早我们不能终老 提交于 2019-12-05 19:01:42
Hi I am having trouble with toggling a check box that is in a JList, I wish for when an item is clicked to have the check box tick, and if it is ticked again i want it to toggle to unticked. I want to have it possible to have multiple items to be ticked or unticked without the use of the ctrl or shift keys. public class CustCellRenderer extends JCheckBox implements ListCellRenderer { boolean selected = false; void CustCellRenderer() { setOpaque(true); setIconTextGap(12); } // allows a custom list cell rendering which will enable me to display an icon as well as filename @Override public

Using the ComboBoxEditor interface with Custom JComponent, and allow edit, and display the List

我们两清 提交于 2019-12-02 09:10:43
I was checking the documentation. https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html https://alvinalexander.com/java/jwarehouse/openjdk-8/jdk/src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java.shtml http://www.java2s.com/Tutorials/Java/javax.swing/ComboBoxEditor/Java_ComboBoxEditor_getEditorComponent_.htm ... and I'm trying to use my Custom ComboBox implementing the interface ComboBoxEditor . Here my complete Code... I hava one JPanel with JComponents ... class ThePanel extends JPanel { private Font intFont = new Font("Monospaced", Font.PLAIN, 8); private

How to add two columns in a Jlist?

一笑奈何 提交于 2019-12-01 10:13:15
问题 I found a Dual JList sample code, but I need two columns in a Jlist . How to add two columns in a Jlist ? I tried to use ListCellRenderer , but I failed to add elements to the model. Here's the code show in webpage with image. 回答1: You mean something like this? I'd start by having a read through How to Use Tables The Main frame... public class DualTableFrame extends JFrame { private JTable leftTable; private JTable rightTable; private JButton addButton; private JButton removeButton; public

display a non-selectable default value for JComboBox

倖福魔咒の 提交于 2019-12-01 06:17:10
I have a JComboBox that contains three Items {"Personel", "Magasinier", "Fournisseur"} . I want this JComboBox to display the value "Choisir une option :" , which is a non-selectable value. I tried this code after initComponents(); : this.jComboBox1.setSelectedItem("Choisir une option :"); but it doesn't work. How can I do that ? You could override the selection code in your JComboBox model, with code such as the following SSCCE: public class JComboExample { private static JFrame frame = new JFrame(); private static final String NOT_SELECTABLE_OPTION = " - Select an Option - "; private static

display a non-selectable default value for JComboBox

时光毁灭记忆、已成空白 提交于 2019-12-01 05:29:10
问题 I have a JComboBox that contains three Items {"Personel", "Magasinier", "Fournisseur"} . I want this JComboBox to display the value "Choisir une option :" , which is a non-selectable value. I tried this code after initComponents(); : this.jComboBox1.setSelectedItem("Choisir une option :"); but it doesn't work. How can I do that ? 回答1: You could override the selection code in your JComboBox model, with code such as the following SSCCE: public class JComboExample { private static JFrame frame =

Swing JList with multiline text and dynamic height

假如想象 提交于 2019-11-28 00:47:15
I already read/tried these posts but that didn't help: Display multiple lines within a Jlist cell How to get multiline for a Jlist text? Problem displaying components of JList What I need is a ListCellRenderer which returns a panel with an icon on the left and a text of dynamic length on the right (like in any forum: on the left a user avatar, on the right the post text). The texts are NOT known to me, so I can't set a fixed cell height. Further, the text length differs from list cell to list cell. So every list cell needs its own height depending on the length of the text. Actually a really

Swing JList with multiline text and dynamic height

馋奶兔 提交于 2019-11-26 21:47:08
问题 I already read/tried these posts but that didn't help: Display multiple lines within a Jlist cell How to get multiline for a Jlist text? Problem displaying components of JList What I need is a ListCellRenderer which returns a panel with an icon on the left and a text of dynamic length on the right (like in any forum: on the left a user avatar, on the right the post text). The texts are NOT known to me, so I can't set a fixed cell height. Further, the text length differs from list cell to list