
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to right align the text in a ComboBox in Java
To right align the text in a JComboBox, use the following:
ComponentOrientation.RIGHT_TO_LEFT
The following is an example to right align the text in a ComboBox:
Example
import java.awt.Component; import java.awt.ComponentOrientation; import javax.swing.DefaultListCellRenderer; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JList; public class SwingDemo extends JFrame { public SwingDemo() { JComboBox<String> combo = new JComboBox<String>(); combo.setRenderer(new MyListCellRenderer()); combo.addItem("One"); combo.addItem("Two"); combo.addItem("Three"); combo.addItem("Four"); combo.addItem("Five"); getContentPane().add(combo, "North"); setSize(600, 400); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args) { new SwingDemo().setVisible(true); } } class MyListCellRenderer extends DefaultListCellRenderer { @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); c.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); return c; } }
Output
- Related Questions & Answers
- How to align text to the right in ttk Treeview widget?
- How to right-align a menu in the menu bar with Java?
- How to align a column right-adjusted in MySQL?
- How to align JLabel text vertically top in Java?
- Align Dropdown to the right with Bootstrap
- How to edit a comboBox in JavaFX?
- How to disable a Combobox in Tkinter?
- How to align text to the left in Tkinter Label?
- Right align a Bootstrap dropdown menu
- How to align axis label to the right or top in Matplotlib?
- Align the text of a document with CSS
- Align the text of a paragraph with CSS
- How to create a ComboBox using JavaFX?
- How to Justify Text using text-align & text-justify CSS Properties?
- How to center align text in table cells in HTML?
Advertisements