Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

java - JLabel with multiple lines and alignment to the right

I searched through many posts and figured out that JLabel supports HTML. So I can do

JLabel search  = new JLabel("<html>Search<br/> By:</html>");

to get multiple lines. Above code will result in

Search  
By:  

However, What I want is something like

Search  
   By: 

Adding spaces before "By:" will work only when the window is not resizable(And very silly lol). Can anyone tell me how to modify this code to make it work as I wanted?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Slightly simpler HTML than seen in @MadProgrammer's answer:

new JLabel("<html><body style='text-align: right'>Search<br>By:");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...