jcombobox

Making JComboBox transparent

£可爱£侵袭症+ 提交于 2020-01-23 12:47:45
问题 I have a problem with making JComboBox transparent. I tried setting opaque to false and alpha of background 0 but it doesnt work. I guess that i need to change some class that does rendering or something similar.And here is the code.. import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.JFrame; import javax.swing.JComboBox; import javax.swing.JTextField; import javax.swing.plaf.basic.BasicComboBoxUI; import java.awt.Color; public class App {

How to populate a JComboBox from an ArrayList?

放肆的年华 提交于 2020-01-17 14:48:12
问题 I've got an ArrayList of objects, and all the objects have names. How can I populate a JComboBox with those names? I've looked online and found nothing so far. There are some resources, but they tend to go with a hardcoded version, which is useless. Since I don't have any code yet showing what I'm doing, I can't attach any. 回答1: JComboBox works with Array or Vector . You should use .toArray() method in the ArrayList to create an array. String[] names = namesList.toArray(new String[0]); then

JPanel not refreshing upon selection with JComboBox

允我心安 提交于 2020-01-14 14:45:31
问题 I am attempting to write a pretty short class that "ties" a JPanel to a JComboBox. I think I have the logic down, but nothing happens when I select something new using the JComboBox... Here is (more or less) my code: private DisplayPanel currentDisplay; //a displaypanel is simply an extended JPanel with an id field, and an overriden .equals() method private JComboBox selector; private List<DisplayPanel> displays; public SelectionPanel(DisplayPanel panel){ displays = new ArrayList<DisplayPanel

JPanel not refreshing upon selection with JComboBox

蓝咒 提交于 2020-01-14 14:45:09
问题 I am attempting to write a pretty short class that "ties" a JPanel to a JComboBox. I think I have the logic down, but nothing happens when I select something new using the JComboBox... Here is (more or less) my code: private DisplayPanel currentDisplay; //a displaypanel is simply an extended JPanel with an id field, and an overriden .equals() method private JComboBox selector; private List<DisplayPanel> displays; public SelectionPanel(DisplayPanel panel){ displays = new ArrayList<DisplayPanel

Filtering JComboBox

会有一股神秘感。 提交于 2020-01-13 06:37:20
问题 At beginning I will say that I don't have in mind auto-complete combobox, but rather having a "setFilter(Set)" method in my combobox, so it displays what is in the set. I was unable to achieve that effect, trying different approaches and I think it's the view responsibility to filter what it displays, so I should not extend ComboBoxModel. This is what I have so far (main includes the case which doesn't work): import java.awt.*; import java.util.Set; import javax.swing.*; public class

How to disable certain items in a JComboBox

做~自己de王妃 提交于 2020-01-11 12:06:01
问题 I have a ComboBox in which I have 8 Items out of which I want to display all but on a certain condition, the user should only be able to select the first two of them, so I have programmed that if the condition is true and the user chooses any other option then it shows up a Message Box showing "You cannot choose this" and then selecting the default automatically. So far so good. But now the thing is that the user cannot make out by seeing the options of JComboBox that which ones can he select

Open JPopupMenu from opened JComboBox

◇◆丶佛笑我妖孽 提交于 2020-01-11 10:34:25
问题 I'd like to change OOTB behaviour of combobox, to freeze it after right mouse button click (detecting which button was clicked is easy, so that's not the point) and open JPopupMenu istead of choosing that entry. So - how to disable choosing entry on given condition and use custom behaviour then? I tried to start by adding mouse listeners to all combobox components, but without success - nothing changed import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.MouseAdapter

Change Cell Editor for specific Cells with AbstractTableModel

别等时光非礼了梦想. 提交于 2020-01-11 07:21:35
问题 I have a written an AbstractTableModel for my JTable in my application. I see from tutorials that I can make the column to have a combobox by getting the column model and then the specific column for example: TableColumn sportColumn = table.getColumnModel().getColumn(2); ... JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Chasing toddlers"); comboBox.addItem("Speed reading"); comboBox.addItem("Teaching high school");

Can not write editable JComboBox

烈酒焚心 提交于 2020-01-07 05:22:06
问题 I'm doing a search on the database using an editable JComboBox, but when it comes to writing, only accepts write me a letter and any amount of numbers, how I can do that allows me to write letters and numbers? The following code accepts only numbers, backspace key, enter key, but not letters. comboBusqueda.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { String cadenaEscrita = comboBusqueda.getEditor().getItem().toString(); if (evt

Alignment resets when using setEditable() for a JComboBox

谁都会走 提交于 2020-01-06 18:46:00
问题 class RuleComboBox extends JComboBox { public RuleComboBox() { super(); this.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"abc", "defg"})); ((JLabel) this.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER); } } The getRenderer() line aligns the text to centre. When I use ruleComboBox1.setEnabled(false) and ruleComboBox1.setEditable(true) , the text aligns back to the left which I don't want. How can I stop this? I should explain that I'm using setEditable(true) to keep