Tag: jcombobox

JCombobox focusLost没有解雇 – 为什么会这样?

我的代码中有一个JCombobox 。 我添加了FocusLost event 。 但无论如何它并没有被解雇。 我已经尝试了很多时间,但没有找到解决方案。 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(“index=” + jcbItemType.getSelectedIndex()); } 但是在控制台中没有打印出来 请告诉我我做错了什么。

JComboBox动作监听器

我有这个问题。 我有多个JComboBoxes(共5个)。 对于每个comboBox,我添加一个ActionListener,但所有这些都是相同的ActionListener,名为: ComboBoxActionPerformed(java.awt.event.ActionEvent e) 当执行该动作时,我会查看事件(e)并执行: JComboBox c = ((JComboBox)e.getSource()); //DO WORK relating to c as thats the combobox that triggered. 但问题是,当我在任何combobox中更改某些内容时,Action总是由我附加actionlistner的最后一个combobox触发。 有谁有任何想法? 然后我切换到ItemListner。 这就是我正在做的事情 class MyActionListner implements ItemListener { //STUFF @Override public void itemStateChanged(ItemEvent evt) { //DO STUFF } } public JComboBox createCombo() { JComboBox box = new JComboBox(); box.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “val1”, […]

java comboBox自动完成

有人可以告诉我如何更改此代码以进行自动选择,我可以编写不存在的项目,因为它不会让我写新项目。 public class ComboBoxFill extends PlainDocument { ComboBoxModel model; JComboBox comboBox=new JComboBox(); JTextComponent editor; public ComboBoxFill(ComboBoxModel model, JComboBox comboBox,JTextComponent editor) { this.model = model; this.comboBox=comboBox; this.editor=editor; } public void insertString (int offs,String str,AttributeSet a) throws BadLocationException { String currentText=getText(0,getLength()); String beforeOffset=currentText.substring(0,offs); String afterOffset=currentText.substring(offs,currentText.length()); String futureText = beforeOffset+str+afterOffset; Object item =lookupItem(futureText); if (item!=null) { comboBox.setSelectedItem(item); }else […]

JComboBox返回值

用什么方法返回用户选择的选择? JPanel ageSelection = new JPanel(); JLabel age = new JLabel(“Age:”); ArrayList ageList = new ArrayList(); for (int i = 1; i <= 100; ++i) { ageList.add(i); } DefaultComboBoxModel modelAge = new DefaultComboBoxModel(); for (Integer i : ageList) { modelAge.addElement(i); } JComboBox ageEntries = new JComboBox(); ageEntries.setModel(modelAge); ageEntries.addActionListener(new putInTextListener()); ageSelection.add(age); ageSelection.add(ageEntries); class putInTextListener implements ActionListener […]

JComboBox更改下拉弹出窗口

基本上是在其派生的JTextField下面显示的JComboBox的弹出窗口,如何改变JComboBox弹出窗口的方向,并在顶部/上方显示JComboBox的弹出窗口 编辑:基本JComboBox的代码示例 import java.awt.Dimension; import javax.swing.*; import javax.swing.plaf.basic.BasicComboBoxRenderer; public class HighRowCombo { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new HighRowCombo().makeUI(); } }); } public void makeUI() { Object[] data = {“One”, “Two with text”, “Three with long text, with long text,with long text “}; JComboBox comboBox = […]

java swing多列自动完成combobox

我需要有效的产品项目搜索GUI到销售点应用程序,目前我在文本字段中使用弹出窗口,它包含到表格但效率不高。 在我的弹出窗口中只显示产品代码我需要显示其他产品细节,如CODE,类别,名称,价格等..以确定正确的产品。 ![在此处输入图像说明] [1] 以下图片是我的要求。 //////////////////////////////我有编辑mr.splungebob的答案来构建AutoCompleatecombobox,但它有List>过滤的问题请查看代码并帮助我开发它。 以下是我为回答// DetailedConboBox而添加的代码 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package test; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Point; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.plaf.basic.BasicComboPopup; import javax.swing.plaf.basic.ComboPopup; import javax.swing.plaf.metal.MetalComboBoxUI; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableColumn; […]

为什么JComboBox会忽略PrototypeDisplayValue

与这两个post@iMohammad相关联, 使用JButton增加/减少textArea中的字体大小和单击JButton Java时更改字体样式 …,我面临着来自JComboBox的非常有趣的问题,方法是将setPrototypeDisplayValue作为参数传递对于JComboBox’s size在屏幕上JComboBox’s size 请问如何动态调整JComboBox大小取决于Font ,同样适用于我在sscce中尝试过的另一个JComponents import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ComboBoxFontChange extends JFrame { private static final long serialVersionUID = 1L; private JComboBox cbox = new JComboBox(); private JTextField tfield = new JTextField(“Change”); private JLabel label = new JLabel(“Cash”); private JButton button = new JButton(“++ Font”); private JTextField text; […]

设置JComboBox PopupMenu的大小

我正在编写一个扩展JComboBox的自定义组件。 我的问题是,如果我要添加或删除项目,PopupMenu将不会实现其大小。 所以列表中有2个项目,但是如果我在PopupMenu中有2个“空”项目之前有4个项目。 我发现的唯一解决方法是做(在JIntelligentComboBox.java第213行) this.setPopupVisible(false); this.setPopupVisible(true); 但结果将是一个闪烁的PopupMenu 🙁 那么我还能做些什么来刷新/重绘PopupMenu而不会闪烁? 用于测试: 组件和一点测试程序 要产生我的问题,你可以: 输入“e” 按“返回” 输入“m” 提前致谢 编辑:我的目标是一个ComboBox,其行为类似于Firefox或Chrome中的地址栏,我想显示包含类型字符的PopupMenu的所有项目。 cboxtester.java: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.plaf.basic.BasicComboBoxRenderer; public class cboxtester extends JFrame { private DefaultComboBoxModel dcm = new DefaultComboBoxModel(new Object[][] {new Object[] {“Mittagessen”, “”, 0}, new Object[] {“Essen”, […]

更改背景颜色可编辑JComboBox

我正在编写一个JFrame表单中的可编辑combobox,但我想改变背景颜色。 程序如何工作:如果我点击“按”按钮,那么combobox的背景需要变成黑色。 我试过了: 1。 cbo.setBackground(Color.BLACK); 但它没有做任何事情 2 cbo.getEditor().getEditorComponent().setBackground(Color.BLACK); ((JTextField) cbo.getEditor().getEditorComponent()).setOpaque(true); 做这个: 代码示例: public class NewJFrame extends javax.swing.JFrame { private JComboBox cboCategorie; public NewJFrame() { initComponents(); cboCategorie = new JComboBox(); cboCategorie.setBounds(10, 10, 250, 26); cboCategorie.setVisible(true); cboCategorie.setEditable(true); this.add(cboCategorie); } private void pressActionPerformed(java.awt.event.ActionEvent evt) { cboCategorie.getEditor().getEditorComponent().setBackground(Color.BLACK); ((JTextField) cboCategorie.getEditor().getEditorComponent()).setOpaque(true); } 我正在使用Java JDK7 任何sugestions?

将项添加到JComboBox

我在面板上使用了一个combobox,据我所知,我们只能添加带有文本的项目 comboBox.addItem(‘item text’); 但有时我需要使用项目和项目文本的一些值,如在html中选择: Item Text 有没有办法在combobox项目中设置值和标题? 现在我使用哈希来解决这个问题。