Arrow Farbe bei JComboBox

Chowkah

Neues Mitglied
Hey zusammen,

ich hätte eine kleine Frage zur JComboBox, auf die ich bis jetzt im Netz noch keine wirkliche Antwort finden konnte.

Ich würde gerne eine farbige JComboBox erstellen, was soweit ja auch kein Problem ist, jedoch lässt sich die Farbe des Arrows nicht ändern.

Hier mal ein kleines Bild zur Verdeutlichung:

Bildschirmfoto 2014-11-20 um 12.17.53.png

Und mein Codeausschnitt:

JComboBox tag = new JComboBox(tageBox);

tag.setOpaque(true);
tag.setBorder(BorderFactory.createLineBorder(Color.GRAY));
tag.setBackground(Color.GREEN);
tag.setEditable(true);
tag.getEditor().getEditorComponent().setBackground(Color.GREEN);


Ich wäre sehr froh, wenn mir hierbei jemand helfen könnte.

Vielen Dank im Voraus!
 
eine Möglichkeit ist das verwendete UI Delegate zu erweitern, in der configureArrowButton Methode kann man die Farbeigenschaft des Arrowbuttons anpassen. beim Beispiel wurde das Metal LookAndFeel verwendet, muß man entsprechend anpassen

Java:
import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.plaf.metal.MetalComboBoxUI;

public class ComboBoxArrowColor extends JFrame {

	public ComboBoxArrowColor() {
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setBounds(200, 200, 300, 300);
		getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));

		JComboBox<String> combo = new JComboBox<>(new String[] { "blablabla" });
		combo.setUI(new MyComboBoxUI());
		add(combo);
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				startApplication();
			}

		});
	}

	protected static void startApplication() {
		new ComboBoxArrowColor();
	}

	public class MyComboBoxUI extends MetalComboBoxUI {

		@Override
		public void configureArrowButton() {
			super.configureArrowButton();
			arrowButton.setBackground(Color.green);
		}

	}

}

Anhang anzeigen 7141
 
Zuletzt bearbeitet:

Neue Themen


Zurück
Oben