jcombobox

Synchronize a jCombobox with a MySQL Table

坚强是说给别人听的谎言 提交于 2019-12-06 06:53:47
I've created a database application with the NetBeans GUI-Designer. GUI with Comboboxes (Bound to MySQL databasetables user and team): on Button new -> jDialog - executes a query to store a new user in database: Problem: Combobox is updated at the programstart but not while running the program. Question: Is it possible to update the entries in my combobox directly when a new user or team is saved? And how could I Implement this? Edit: Here is what I do when clicking on the saveButton in the JDialog : int k=st.executeUpdate( "INSERT INTO User (username) " + " VALUES ('"+ name + "')"); //Here I

JComboBox search list

我与影子孤独终老i 提交于 2019-12-06 06:10:29
I w'd like make a JComboBox that contents could be searchable. I tried AutoCompleteDecorator, GlazedLists, SwingLabs, JIDE, Laf-Widget , but all of the cannot search by second keyword. For example, in this code possible search by 1st letter and this content includes just one word. this.comboBox = new JComboBox(new Object[] { "Ester", "Jordi", "Jordina", "Jorge", "Sergi" }); AutoCompleteDecorator.decorate(this.comboBox); If JComboBox content consists 2 or 3 words, for example: "Ester Jordi" or "Jorge Sergi", in this case if I enter "Sergi", JComboBox don't show nothing, because it can recognize

Java: How to remove default KeyStrokes from any JComponent?

浪子不回头ぞ 提交于 2019-12-06 01:28:19
问题 I want to control which keystroke belong to which Jcomponent . I even want to get how to remove the default keystrokes associated with a Jcomponent and replace them with other favourite keystrokes. I followed this oracle tutorial, it gives an example with JButton, I tried it and it works fine, but when I try it with JComboBox it doesn’t work! What exactly I tried is removing the SPACE key, that is prevent the JComponent from responding to SPACE presses I used this code to remove the SPACE key

Pick Color with JComboBox Java Swing

核能气质少年 提交于 2019-12-05 17:16:57
I have a JComboBox where I want for user to select color. JComboBox is displaying just the colors, without any text. I've come up with this solution. Please advise me if this is good or it should be avoided and why. I am new to Swing and Java in general so please be patient :) public class ToolBar{ private MainFrame mainFrame; public ToolBar (MainFrame mainFrame) { this.mainFrame = mainFrame; } public JPanel getToolBar(){ JPanel toolbarPanel = new JPanel(new FlowLayout(FlowLayout.LEADING,2,2)); toolbarPanel.setPreferredSize(new Dimension(mainFrame.getScreenWidth(),60)); toolbarPanel.setBorder

The Stubborn JComboBox

一曲冷凌霜 提交于 2019-12-05 14:32:26
I have a JComboBox shown in the code below. When the program starts its actionPerformed event fires up immediately causing some null pointer exceptions so I want to start with none of the elements selected. However, for some reason it does not work (it always start with displaying "USD/TRY" whatever I do). Anyone has any idea ? JComboBox comboBox = new JComboBox(new String[]{"USD/TRY", "EUR/TRY", "GBP/TRY"}); comboBox.setSelectedIndex(-1); // doesnt change anything comboBox.setSelectedIndex(2); // doesnt change anything comboBox.setSelectedItem(null); // doesnt change anything UPDATE: Building

How do I detect that a JComboBox is empty?

江枫思渺然 提交于 2019-12-05 14:08:23
How do I detect that a JComboBox is empty? Is it something like: combobox.isEmpty() What's wrong with JComboBox.getItemCount() ? If this method returns 0 , the component is empty. if(JComboBox.getItemCount() != 0){ //JComboBox is not empty - do something.. } I suppose you're looking for getItemCount() method 来源: https://stackoverflow.com/questions/9161659/how-do-i-detect-that-a-jcombobox-is-empty

JComboBox in JTable

房东的猫 提交于 2019-12-05 13:13:44
I've a JComboBox in 3rd and 4th column of a JTable but I don't know how to get its items...the problem isn't the method to get items but the cast JComboBox combo=(JComboBox) jTable1.getColumnModel().getColumn(3).getCellEditor(); Can you help me please? The JComboBox is wrapped in a CellEditor . You must retrieve the wrapped component, for example when using DefaultCellEditor : DefaultCellEditor editor = (DefaultCellEditor)table.getColumnModel().getColumn(3).getCellEditor(); JComboBox combo = (JComboBox)editor.getComponent(); Read this tutorial on how to use JCombobox as editor in JTable. http:

Custom Font for JComboBox

和自甴很熟 提交于 2019-12-05 12:05:30
I would like that to know how to change the Font for the displayed/selected value in a JComboBox . E.G. The upper rendering of Aharoni (image courtesy of this answer ). I can change the list values with a renderer like this: public class JComboBoxItalic extends BasicComboBoxRenderer { protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer(); public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Font theFont = null; JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value

How can I make combobox's list wider?

风格不统一 提交于 2019-12-05 10:59:01
import javax.swing.*; public class test { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(120,80); JComboBox cb = new JComboBox(); cb.addItem("A very long combo-box item that doesn't fit no. 1"); cb.addItem("A very long combo-box item that doesn't fit no. 2"); frame.add(cb); frame.validate(); frame.setVisible(true); } } How can I make combo-box items to appear in the way that all their text is visible? Now I have something like this: I don't want to change size of combo-box

Swing BoxLayout problem with JComboBox without using setXXXSize

无人久伴 提交于 2019-12-05 10:48:07
here's an SSCCE: import java.awt.Color; import java.awt.Dimension; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; public class BoxLayoutTest extends JFrame { public BoxLayoutTest(){ JPanel main = new JPanel(); main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); main.setBackground(Color.red); this.add(main); JPanel northPanel = new JPanel(); JPanel middle = new JPanel(); middle.setLayout(new BoxLayout(middle, BoxLayout.X_AXIS)); middle.add(new JButton("FOO")); middle.add(Box