问题标签 [jcombobox]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
668 浏览

java - 为什么 JComboBox 似乎添加了多个项目实例?

这个 Java Swing JComboBox 是根据对系统配置的更改进行修改的。在示例图像中,“Press to Select”是未选择任何内容且配置中有一个“Test Unit”,但“Press to Select”在下拉菜单中显示两次的情况。附加的“Press to Select”项目的行为类似于项目 0,因此它可以正常工作,但这样看起来很糟糕。有任何想法吗?

替代文字

0 投票
1 回答
4327 浏览

java - JCombobox为每个项目添加不同的颜色

我对 Jcombobox 有疑问...例如,我有一个 gui,其中包含一个 jcombo 框和一个按钮...在 Jcombo 框中,我添加了字符串数组对象,例如颜色 1、颜色 2、颜色 3:字符串 [] colors = {"Color 1","Color 2","Color 3"}。我可以在单击按钮时使用颜色选择器选择颜色,它只会应用于按钮....但我想设置前景色到 tat 组合框中的“颜色 1”、“颜色 2”.. 例如:如果我通过按钮选择颜色为红色,则它应仅在 jcombobox 上应用前景色“选定项目”(示例颜色 1 应显示为红色,其他应该是默认颜色!

...我是Java的新手...如果有人知道,请帮助我..谢谢

0 投票
2 回答
1030 浏览

java - 具有多行单元格的表中的 JComboBox 大小问题

我最近遇到了一个问题,我需要一个可以换行文本并在换行时增加行高的字段,类似于 Microsoft Excel。我设法让它正常工作,唯一的问题是该表包含多个 JComboBoxes。当行高从环绕文本的字段开始增加时,JComboBox 窗口和 ArrowButton 的大小也会增加。我为 JComboBox 字段使用 DefaultCellEditor,并创建了我自己的编辑器/渲染器以与 JTextArea 字段一起使用。一旦选择了 JComboBox 的值,该值就会在字段中正确显示,唯一的问题是当我选择值时,JComboBox 窗口和 ArrowButton 可能会很大,具体取决于行的大小。有什么办法可以增加行高,但是 JComboBox 字段高度是否保持不变而不是增长以填充它所在的列?我想我可能还需要为 JComboBox 字段创建一个自定义单元格编辑器,而不是使用默认值。提前致谢!

0 投票
2 回答
380 浏览

java - JComboBox 导致运行时错误

我正在尝试用 Java 进行一些 GUI 开发,当我添加以下代码时,在类的初始化过程中出现运行时错误:

我得到的错误是:

有谁知道为什么?

宾亚明

0 投票
2 回答
25246 浏览

java - JComboBoxes - Using setModel to access Objects (in Swing)

Quick background, I am using Netbeans to develop this (I don't have much experience with Swing and have lost points on experience at the chance to gain development speed). In Netbeans it is obviously restrictive as to what code you can modify to stop novice users breaking the code (which I have already amusingly done once) Anyway, I have a class of Objects, these Objects have a name property. Within the application I have directly initialised an array of these objects and called them "things";

The contents and names are deliberately inane as this is a test to get this working (rather than pulling apart a part written program). After some research and reading I have discovered that I "should" be able to load objects into the setModel parameter using the following code;

This hasn't worked, and despite my best efforts to google this seems to be too specific to nail down a decent answer. The end result is that I would like to have; "The first thing" and "The second thing" displayed within the drop down list, and then obviously I can expand on this within the real program by referencing any other data held in that object on the screen.

Any suggestions or even pointers to help me think this out would be appreciated.

0 投票
2 回答
20687 浏览

java - 在 JComboBox 中显示图像

我需要在 JComboBox 中显示图像

0 投票
1 回答
8879 浏览

java - JComboBox 设置所选项目无法正常工作

我正在尝试使用以下项目填充我的 JComboBox:

}

但是我在使用 JComboBox 时遇到了问题setSelectedItem。我传递setSelectItem了一个 int,正如您从上面看到的那样,我试图确保它在正确的时候被选中。我遇到的问题是只检查了当前选择的项目,这对我来说很奇怪。我通过添加打印语句验证了这一点,该语句只打印一次..

有任何想法吗?

谢谢

0 投票
2 回答
827 浏览

java - 在 Windows L&F 中将 JButton 用作 ComboBoxEditor 时,如何消除间隙?

我正在尝试将 JButton 用作 JComboBox 中的编辑器。在 Mac OS X 上这看起来不错,但在使用系统外观的 Windows 上,JButton 编辑器和组合按钮本身之间留下了一个难看的差距:

显示 JButton 和组合按钮之间间隙的图像

这是用于生成对话框的测试代码:

0 投票
1 回答
45065 浏览

java - ComboBox - 打印出选定的项目

我有点卡住了。我想不出比这更大的问题,所以我要从根源上最终建立自己的道路!

我无法在组合框中打印所选项目,目前我有一个ActionListener

我希望每次更改所选项目时都会将其打印到控制台,但事实并非如此。不过,这应该很容易!

谢谢

0 投票
1 回答
974 浏览

jtable - JTable Cell中的JComboBox未显示

我正在尝试使用 ComboBoxes 编辑我的 JTable 中某个列的单元格的内容。因此,我只需使用 JTables 官方 Java 教程 (http://download.oracle.com/javase/tutorial/uiswing/components/table.html) 中的代码。相关代码最终看起来像这样:

问题是当我单击该列中的单元格时,组合框不会出现。我完全能够编辑单元格,但只能通过输入它们。为什么组合框不显示?