如何更改ComboBoxEditor的边框? [英] How do i change the border of the ComboBoxEditor?

查看:53
本文介绍了如何更改ComboBoxEditor的边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我的对话框上有一个组合框.

如何更改其编辑区域上边框的颜色?

ComboBox设置为不可编辑(意味着,在运行项目时,我只能选择其现有列表的内容,而不能编写自己的内容),并且我不想更改它.

如果我尝试使用

  UIManager.put("ComboBox.border",BorderFactory.createLineBorder(dark_sand)); 

它只是在Whoole ComboBox周围增加了一个边框.
但是我只想更改编辑区域的现有两色边框.


这显示了我的对话框的实际外观.

  UIManager.put("Button.border",BorderFactory.createLineBorder(dark_sand)); 

也会设置组合框按钮的边框.
这就是为什么我只想更改ComboBoxEditor上的现有边框.


这就是我想要的样子(用Gimp编辑)

丰富的UIManager属性或方法调用会更改ComboBox的此部分的边框

解决方案

您能告诉我如何找到该实例以设置其边界吗?

首先阅读 JComboBox 的API.

您将找到一种方法,用于获取组合框的 ComboBoxEditor .

当您获得 ComboBoxEditor 时,您将读取其API,以找到用于获取用于编辑器的实际组件的方法,默认情况下,该组件为 JTextField ./p>

然后您设置文本字段的 Border .

Hello i have a combobox on my dialog.

How do i change the color of the border on it´s editor-area?

The ComboBox is set to not editable (means, while running the project, i can only pick a content of it´s existing list, but not writing own content) and i don´t want to change it.

If i try to use

UIManager.put("ComboBox.border", BorderFactory.createLineBorder(dark_sand));  

It add´s only an extra border around the whoole ComboBox.
But i just want to change the existing two-color-border of the editing-area.


This shows the actual look of my Dialog.

UIManager.put("Button.border", BorderFactory.createLineBorder(dark_sand));

will set the border of the Combobox-Button too.
This is why i want to change only the existing border at the ComboBoxEditor.


This is how i want it look like (edited with Gimp)

Wich UIManager property or method-call changes the border of this part of the ComboBox

解决方案

can you show me how to find this instance to set it´s border?

Start by reading the API for JComboBox.

You will find a method to get the ComboBoxEditor for the combo box.

When you get the ComboBoxEditor you then read its API to find the method used to get the actual component used for the editor, which by default is a JTextField.

Then you set the Border of the text field.

这篇关于如何更改ComboBoxEditor的边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆