jcombobox

editable JComboBox

别等时光非礼了梦想. 提交于 2019-12-19 05:59:12
问题 I have editable JComboBox and wish to add values to it from its input,e.s when I typing something in JComboBox and press enter I want that text appear in JComboBox list : public class Program extends JFrame implements ActionListener { private JComboBox box; public static void main(String[] args) { new Program().setVisible(true); } public Program() { super("Text DEMO"); setSize(300, 300); setLayout(new FlowLayout()); Container cont = getContentPane(); box = new JComboBox(new String[] { "First"

How to update JComboBox instances in Swing?

≯℡__Kan透↙ 提交于 2019-12-19 04:11:29
问题 I've 3 comboboxes, upon selecting first combobox, the rest should be updated but my code doesn't seems to be working. Please help in this guys. Here is my code(since my code very long so I'll write error part only). // example code public class GuiComponents { JComboBox<String> comboBox1, comboBox2, comboBox3; public GuiComponents() { ......... ......... String[] element1 = {"item1", "item2", "item3"}; String[] element2 = {"item1", "item2", item3}; String[] element3 = {"item1", "item2",

Why isn't getSelectedItem() on JComboBox generic?

五迷三道 提交于 2019-12-18 12:45:22
问题 JCombobox in Java 7 has been updated to use generics - I always thought it was a bit of an oversight that it didn't already so I was pleased to see this change. However, when attempting to use JCombobox in this way, I realised that the methods I expected to use these generic types still just return Object. Why on earth is this? It seems like a silly design decision to me. I realise the underlying ListModel has a generic getElementAt() method so I'll use that instead - but it's a bit of a

Why isn't getSelectedItem() on JComboBox generic?

余生长醉 提交于 2019-12-18 12:44:59
问题 JCombobox in Java 7 has been updated to use generics - I always thought it was a bit of an oversight that it didn't already so I was pleased to see this change. However, when attempting to use JCombobox in this way, I realised that the methods I expected to use these generic types still just return Object. Why on earth is this? It seems like a silly design decision to me. I realise the underlying ListModel has a generic getElementAt() method so I'll use that instead - but it's a bit of a

how to compute the result of two integer values but get the additive or multiplicative operator from a jComboBox in java

a 夏天 提交于 2019-12-18 09:36:55
问题 assume i have integer variables a,b and c. c = a + b; or c = a - b; or c = a / b; or c = a * b; As you can see, the computation operator needs to be passed dynamically at run time. So i have a jComboBox of operators, so a user will select either a +, -, * or / from the jcomboBox. how do i get the jCombobox selectedItem(which will be either /, *, -, or + ) and use it in getting the value of c. Eg. if the user selects *, then the expression should be c = a * b else if the user selected say +,

How do you change border of the pop up section of a JComboBox?

别说谁变了你拦得住时间么 提交于 2019-12-18 09:21:50
问题 I wan't to change the border of the popup/selection part of the JComboBox. Note that the UI is BasicComboBoxUI I've tried: weaponCB.setRenderer(new DefaultListCellRenderer() { @Override public void paint(Graphics g) { setBorder(whiteBorder) //whiteBorder is a white border super.paint(g); } }); but it gave me this: and: for (int i=0; i<weaponCB.getComponentCount(); i++) { if (weaponCB.getComponent(i) instanceof AbstractButton) { ((AbstractButton)weaponCB.getComponent(i)).setBorder(whiteBorder)

How to make JComboBox selected item not changed when scrolling through its popuplist using keyboard

筅森魡賤 提交于 2019-12-18 03:24:27
问题 I have a JComboBox component in the panel and ItemListener attached to it. But it gets fired after every up/down keypress (when scrolling though opened popup list). I want to change the selected value after the user accepts selection by pressing for example Enter key. This is not a case when using mouse. When I move mouse over the combobox's list the highlight follows mouse pointer, but selected item is not changed until I press the mouse button. I would like to have the same behavior for

Adding a watermark to an empty JCombobox

為{幸葍}努か 提交于 2019-12-17 20:26:01
问题 I'm trying to reproduce the behavior of the search field of Firefox or Safari, or the search field of stackoverflow.com on the top right of this page. I mean, when there is no text on the editable JComboBox , an instruction text is displayed, like "Type here" or whatever. When the JComboBox is focused the text is removed. If the focus is lost with no text typed, the instruction text comes back. 回答1: Note: Check out Text Prompt for a more complete implementation of the code below with more

java swing multi column autocomplete combobox

橙三吉。 提交于 2019-12-17 16:45:09
问题 I need efficient product item search GUI to Point of sale application, currently I am using pop up in text field and it include to table but it is not efficient. In my popup only show product code I need to show other product detail such as CODE , category, Name ,price etc.. to determine correct product. ![enter image description here][1] Following images are the my requirement. ////////////////////////////// I have Edit mr.splungebob answer to build AutoCompleate combobox , But It has

Set Size of JComboBox PopupMenu

给你一囗甜甜゛ 提交于 2019-12-17 16:39:53
问题 i am programming a custom component which extends a JComboBox. My problem is, the PopupMenu won't actualise its size if i am adding or removing an item. So there are e.g. 2 items in the list, but if there were 4 before i had 2 "empty" items in the PopupMenu as well. The only workaround i found was to do (in JIntelligentComboBox.java line 213) this.setPopupVisible(false); this.setPopupVisible(true); but the result will be a flickering PopupMenu :-( So what else could i do to refresh/repaint