如何让JComboBox中的内容显示在中心? [英] How to let the content in JComboBox display in the center?

查看:219
本文介绍了如何让JComboBox中的内容显示在中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有这个 JComboBox ,我怎样才能将内容集中在里面?

Currently I have this JComboBox, how can I get to center the content inside it?

String[] strs = new String[]{"15158133110", "15158133124", "15158133458"};
JComboBox com = new JComboBox(strs);


推荐答案

您需要创建一个渲染器然后将其应用于JComboBox

You need to create a Renderer then apply it to the JComboBox

DefaultListCellRenderer dlcr = new DefaultListCellRenderer(); 
dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER); 
com.setRenderer(dlcr); 

也导入此,

import javax.swing.DefaultListCellRenderer; 

这篇关于如何让JComboBox中的内容显示在中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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