Java中怎么设置JLabel的字体样式,大小,颜色?

Java中怎么设置JLabel的字体样式,大小,颜色?,第1张

1、打开Myeclipse的相关界面,在Window那里点击Preferences。

2、d出设置的对话框,选择General下的Appearance进入。

3、点击Colors and Fonts按钮,需要在右侧选择Java。

4、选择Java Editor Text Font,并点击Edit。

5、通过设置对应的参数以后,直接确定返回。

6、这样一来会看到图示的结果,即可设置JLabel的字体样式,大小,颜色了。

使用方法

第一种是在listview中配置android:listSelector=”@drawable/list_item_bg”

第二种是在listview的item中添加属性android:background=”@drawable/list_item_bg”

第三种是java代码中使用:

Drawable drawable = getResources().getDrawable(R.drawable.list_item_bg)

listview.setSelector(drawable)

注:列表有时候为黑的情况,需要加上下面的代码使其透明:

android:cacheColorHint="@android:color/transparent"

使用selector设置字体颜色

1

2

3

4

5

6

7

8

drawable/button_font.xml

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="<a href="http://schemas.android.com/apk/res/android">" target="_blank">http://schemas.android.com/apk/res/android"></a>

<item android:state_selected="true" android:color="#FF0000" />

<item android:state_focused="true" android:color="#00FF00" />

<item android:state_pressed="true" android:color="#0000FF" />

<item android:color="#000000" />

</selector>

可以用setFont方法

JButton jb=new JButton("设置字体大小和粗体")

Font f=new Font("华文行楷",Font.BOLD,20)//根据指定字体名称、样式和磅值大小,创建一个新 Font。

jb.setFont(f)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11131058.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存