Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计 » Swing  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 控制JLabel,JButton上文字的格式,换行显示。
scottding

十三部落酋长

CJSDN高级会员


发贴: 1054
积分: 101
于 2002-12-02 13:25 user profilesend a private message to usersend email to scottdingsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
上次和朋友说到要在Label上或者Button上或者messagedialog换行显示文本,或者格式化文本,当时没有什么很好的解决办法,最近看到一些资料,但是还没有找全,和大家共同讨论一下,在Java中的显示的文本是支持html标签的,我们可以控制string为html文本,如果这样的话就可以格式化显示我们所要求输出的文字,比如,我们可以给出一个String str="<html><P align=center>test1</P><font size=24><i><u>tatatatatattest2</u></i></font></html>"大家可以把这个string set到你的Label或者Button或者dialog上,你可以看到什么效果??呵呵,你还可以控制这些代码以得到你想要的一些效果,如果哪位朋友有更多的资料希望能够共同讨论。


作者 Works for the tooltip as well [Re:scottding]
snowbug



CJSDN高级会员


发贴: 418
积分: 130
于 2002-12-02 22:59 user profilesend a private message to usersend email to snowbugsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
This trick works for the popup tooltips as well.


作者 Re:控制JLabel,JButton上文字的格式,换行显示。 [Re:scottding]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2002-12-09 22:40 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
However, the image tag seems not working, even though some books claim it should work.

Anyone tried before?



作者 Re:控制JLabel,JButton上文字的格式,换行显示。 [Re:floater]
snowbug



CJSDN高级会员


发贴: 418
积分: 130
于 2002-12-09 23:08 user profilesend a private message to usersend email to snowbugsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
floater wrote:
However, the image tag seems not working, even though some books claim it should work.

Anyone tried before?


I don't think the img tag can work because image requires different painting mechanism in Swing. However, I think if the requirements gets too complex for this trick to work, you can always write you own class to do the job Smile



作者 Re:控制JLabel,JButton上文字的格式,换行显示。 [Re:scottding]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2002-12-10 01:01 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
In John Zukowski's book "Definitive Guide to Swing for Java 2", 2nd edition, he said it will work, but then he turns to a customized rendering class. That's why I am wondering ...

I tried before, it gave me a broken image icon(like in browser). I thought maybe I put image files in wrong place, so I put it in everywhere along the path from the root. But still the same...



作者 It worked! [Re:scottding]
snowbug



CJSDN高级会员


发贴: 418
积分: 130
于 2002-12-10 02:06 user profilesend a private message to usersend email to snowbugsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
It actually works!!

Here is the code:

import javax.swing.*;
import java.awt.*;

public class Test extends JFrame{

public Test(){
getContentPane().add(new JButton("<html><font color=red>Red</font><img src=\"http://www.cjsdn.com/images/faces/face_aplomadofalcon.gif\"</img></html>"), BorderLayout.CENTER);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

public static void main(String[] args) {
new Test();
}
}


I think you have to use HTTP reference for the image you want to display.


snowbug edited on 2002-12-10 02:07

作者 Re:控制JLabel,JButton上文字的格式,换行显示。 [Re:scottding]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2002-12-10 05:06 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
hehe, that's interesting.

I didn't try this before, launching a web server.

Ideally, we should make it work without a webserver. It would be a little bit demanding for a swing application to have a web server up and running, Smile. But it's something.



作者 Re:控制JLabel,JButton上文字的格式,换行显示。 [Re:scottding]
scottding

十三部落酋长

CJSDN高级会员


发贴: 1054
积分: 101
于 2002-12-10 09:33 user profilesend a private message to usersend email to scottdingsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
呵呵,这个东西真是太神奇了,不知哪位可以提供一点详细的资料?



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923