在Java中的textArea中将字体和颜色设置为字符串 [英] Set font and color to string in textArea in Java

查看:309
本文介绍了在Java中的textArea中将字体和颜色设置为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个关于聊天客户端服务器的练习,所以我没有很多java,

我正在为聊天私密编码。我有一些问题需要你的帮助。

1.我有一个textArea来包含聊天消息,我希望设置字体和颜色与用户名部分相同:



ga_con:你好汤姆。

老虎:嗨结婚。



2.我有一个列表朋友并将它们显示给主聊天(同一个雅虎),但我不知道哪个最佳控件可以显示它们和它们的图标。在这种情况下我们可以改变状态当朋友通过更改他们的图标登录(在线)时,朋友从离线到在线。当我双击nay朋友时,这个控件必须允许m打开私人聊天窗口。



希望尽快得到你的帮助。



P / S:请给出一些代码行



提前感谢

解决方案

< blockquote>首先,这是一项经典的家庭作业。所以我想把编码留给你。



我会定义颜色,也许可以通过JcolorChooser对话框选择。

这些颜色需要应用于文本。为了简单起见,我不会想到一个JTextArea而是一个Scrollpane,我将标签添加到。



这些标签应该是自定义的。他们会保留颜色并将一个或另一个应用于标签:



  public   CustomLabel扩展JLabel {

private final 颜色oColor1,oColor2;

public CustomLabel(){
super (strText);
// 设置颜色
.ignition();
}

private void ignition(){
this .setForeground(oColor1);
}
}





http://www.leepoint.net/notes-java/GUI/components/10labels/12labelfontcolor.html [ ^ ]



如何使用Scrollpane [ ^ ]


Hi all,

I have a exercise about chat client server, so i don''t have lot of java,
I am coding for chat private. I have some problem which need your help.
1. I have a textArea to contain chat message, I want set font and color to user name part the same as:

ga_con: hello Tom.
tiger: hi marry.

2. I have a list friend and display them to main chat(the same yahoo) but i don''t know which best control to display them and their icon.in this case we are can change status of a friend from offline to online when this friend log in(online) by change their icon. this control must allow m open private chat window when i double click on nay friend.

the hope that receive your help soon.

P/S: please give some code line

thank in advance

解决方案

First of all, this is a classic homework task. So I would like to leave the coding to you.

I would define the colors, maybe selectable via a JcolorChooser Dialog.
These colors need to be applied to the text. To make that simpler, I would Not think of a JTextArea but of a Scrollpane, that I add Labels to.

These Labels should be custom. They would hold the colors and apply one or the other to the Label:

public class CustomLabel extend JLabel{

private final Color oColor1, oColor2;

public CustomLabel(){
  super(strText);
  // set colors
  this.ignition();
}

private void ignition(){
  this.setForeground(oColor1);
}
}



http://www.leepoint.net/notes-java/GUI/components/10labels/12labelfontcolor.html[^]

How to use Scrollpane[^]


这篇关于在Java中的textArea中将字体和颜色设置为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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