Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

new line in a Label or a Button

Thread view: 
Marco - 28 Mar 2005 08:09 GMT
It is possible, in awt, to have a phrase divided  in more of one line? I
want display in a Button this:

save
with
name

and not this:

save with name

But if i write:
Button b=new
Button("save"+System.getProperty("line.separator")+"with"+System.getProperty("line.separator")+"name");
I see only strange characters, and not new lines.
Steve W. Jackson - 28 Mar 2005 19:51 GMT
> It is possible, in awt, to have a phrase divided  in more of one line? I
> want display in a Button this:
[quoted text clipped - 12 lines]
> line.separator")+"name");
> I see only strange characters, and not new lines.

Both of the JLabel and JButton classes in Swing support using HTML for
their string values.  I've never used any AWT, so I can't say for
certain whether they do or not -- but I suspect that they do.

So to set up a JButton like you want, you could simply create a new
JButton like this:

JButton btn = new JButton("<html>save<br>with<br>name</html>");

The closing "html" tag isn't strictly necessary, but I consider it bad
form not to close the tag.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

Marco - 28 Mar 2005 20:03 GMT
> So to set up a JButton like you want, you could simply create a new
> JButton like this:
>
> JButton btn = new JButton("<html>save<br>with<br>name</html>");

I read this, but with a Button the result is:

<html>save<br>with<br>name</html>

and not:

save
with
name

I know that swing was wroten in awt, then I think that if I can do anything
with swing, I can do with awt to. Or not? And how?
Thomas Weidenfeller - 29 Mar 2005 08:13 GMT
> It is possible, in awt, to have a phrase divided  in more of one line? I
> want display in a Button this:

You have to implement your very own button, or switch to Swing.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Marco - 29 Mar 2005 17:07 GMT
> You have to implement your very own button

How?
Marco - 29 Mar 2005 18:39 GMT
>> You have to implement your very own button
> How?

import java.io.*;
import java.awt.*;

public class ButtonMultiline extends Button
{
 String[] texts;

 public ButtonMultiline(String[] t)
  {
   super();
   texts=t;
  }
 public void paint(Graphics g)
  {
   super.paint(g);
   Dimension d=this.getSize();
   int dy=d.height/(texts.length+1)+1;
   FontMetrics metricaFont = getFontMetrics(g.getFont());
   for (int i=0;i<texts.length;i++)
    {g.drawString(texts[i],(d.width-metricaFont.stringWidth(texts[i]))/2,dy/4+dy*(i+1));}
  }
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.