jcombobox

Background color of the selected item in an uneditable JComboBox

戏子无情 提交于 2019-11-27 09:31:14
The background color of the selected item in an uneditable JComboBox is a sort of blue: Is there any way to make this a different color, such as white, for example? This should work jComboBox1.setRenderer(new DefaultListCellRenderer() { @Override public void paint(Graphics g) { setBackground(Color.WHITE); setForeground(Color.BLACK); super.paint(g); } }); The background assigned by the renderer is overriden by the selection background color of the JList that is used in the popup for the combo box. Check out the "paintCurrentValue" method of the BasicComboBoxUI class. So the workaround would be:

Item in JComboBox instance of an object

僤鯓⒐⒋嵵緔 提交于 2019-11-27 09:23:11
Hello I have the following code to see if an item in the JComboBox is instance of a class(Persoon). public class ItemChangeListener implements ItemListener { Persoon selectedPerson; RekeningApp app; PersoonView view; public ItemChangeListener(PersoonView view) { this.view = view; } public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) { Object item = event.getItem(); System.out.println("Itemchangelistener " + item); // do something with object if(item instanceof Persoon) { System.out.println("Instance"); this.selectedPerson = (Persoon) item; view

Select item from JCombobox and delete the row in database

有些话、适合烂在心里 提交于 2019-11-27 08:50:46
问题 I am working on a project in which I have a SQLite database with a table called Table1 and values title/location without an ID as column etc... My form has a combobox which I've managed to get it display my DB each entry in one row . Now I want with a button "Delete" to delete the row that I have selected in the combobox and I am kind of lost. Here is my code for the combobox (I think it's fine): private void FillCombo(){ try { String newLine = System.getProperty("line.separator"); Class

Remove border from JComboBox

 ̄綄美尐妖づ 提交于 2019-11-27 08:32:36
问题 Do you know any way to remove the border from a JComboBox in Java? I try the following code public class ComboFrame extends JFrame { public ComboFrame() { JPanel container = new JPanel(); JComboBox cmb = new JComboBox(new String[] { "one", "two" }); cmb.setBorder(BorderFactory.createEmptyBorder()); container.add(cmb); getContentPane().add(container); pack(); } } and public static void main(String[] args) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Add different combobox for each row of a column in a jtable

。_饼干妹妹 提交于 2019-11-27 08:24:00
问题 public class TablePanel extends JPanel implements ActionListener,Serializable { JTable m_table; JComboBox combo,combo1; DefaultTableModel model=new DefaultTableModel(); DefaultComboBoxModel model1=new DefaultComboBoxModel(); DefaultComboBoxModel model2=new DefaultComboBoxModel(); List<String> field; List<String> attrCode; TablePanel() { m_table=new JTable(model); m_table.setBackground(Color.WHITE); model.addColumn("col1"); model.addColumn("col2"); model.addColumn("col3"); model.addColumn(

JComboBox determine if Items are/aren't visible in drop-down list

心不动则不痛 提交于 2019-11-27 08:20:07
问题 I tried to determime for every Items if are or not visible in the JViewPort from JComboBox drop-down list (my Friday OT) EDIT: I don't want to implements MouseListener for Repeats events to System.out.print(...) isn't possible pass JComboBox with JList, declared by JCombo#Model by using SwingUtilities http://download.oracle.com/javase/6/docs/api/javax/swing/SwingUtilities.html , but this APi is out of my... import java.awt.*; import java.awt.event.*; import javax.swing.*; public class

How to avoid firing actionlistener event of JComboBox when an item is get added into it dynamically in java?

99封情书 提交于 2019-11-27 07:58:02
问题 I need your suggestions and guidence on following task. I have a frame which has two JComboBoxes supposed they are named combo1 and combo2, a JTable and other components. At initial stage when frame is visible with above component. The combo1 combobox is filled with some values but no value is selected at initial stage, the combo2 combobox is disabled and the table is empty. I have added an actionListener on combo1 as well as combo2. There are two types of values in combo1 suppose those

Setting a tooltip for a value from JComboBox's Items as CellEditor in JTable

爱⌒轻易说出口 提交于 2019-11-27 07:27:37
问题 I would like to set a tooltip value for the values in a custom combo box. Basically, my combobox contains a list of initials of people - when they hover over i want it to display the fullname of the person. My combo box is basically a cell/column of a JTable that has its own TableCellRenderer and DefaultCellEditor. The list is a JList (inner class within the model) - iv tried setting the 'setToolTipText' method directly but that doesnt seem to work. Here is the code: *Code within the JTable:

Java Editable JCombobox Keylistener event for Enter key

99封情书 提交于 2019-11-27 07:02:25
问题 I have editable JCombobox and I added keylistener for combobox editor component. When user press 'Enter key' and if there is no text on the editable combobox I need to display message box using JOptinoPane. I have done necessary code in keyrelease event and it displays message as expected. Problem is, when we get message box and if user press enter key on 'OK' button of JOptionPane, combobox editor keyevent fires again. Because of this, when user press Enter key on message box, JoptionPane

JCombobox focusLost is not firing-why is that?

℡╲_俬逩灬. 提交于 2019-11-27 06:49:21
问题 I have a JCombobox in my code. I have added the FocusLost event . But it didn't fired anyway. I have tried lots of time but didn't find solution. jcbItemType.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { jcbItemTypeFocusLost(evt); } }); private void jcbItemTypeFocusLost(java.awt.event.FocusEvent evt) { // TODO add your handling code here: System.out.println("name=" + ((Component) evt.getSource()).getName()); System.out.println(