File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes font size, and dialogbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "font size, and dialogbox" Watch "font size, and dialogbox" New topic

font size, and dialogbox


Joined: Oct 10, 2005
Posts: 1
pls,i'am a beginner in java and have being trying to write a code to (1).change the font size of a text.(2). change the font style of a text.(3)use dialog boxes effectively but failed.pls i need to tell me how to go about it and if you can help me with the code
Parth Bhatt
Ranch Hand

Joined: Oct 19, 2005
Posts: 58
The 1st two problems that you've mentioned involve the use of the Font class found in package "java.awt.*"

To change the Font Style and The Font Size use the following constructor of the Font class :

Font font=new Font(String name, int style, int size);

name - is the required font name like Lucida, Arial etc(if you're
on Windows)
style - can be PLAIN, or a bitwise union of BOLD and/or ITALIC(for
size - is the integer value that specifies theh size on the font.

An example of using the above would be :

Font font=new Font("Comic Sans Ms",PLAIN,12);

Once you've created the Font object you can set the font of a Label, TextArea, etc to the perticular Font using the setFont(Font); method. Here's How....

TextArea ta=new TextArea("");
Font font=new Font("Comic Sans Ms",PLAIN,12);


The above call would work even if ta was an object of the Label class. As the method setFont is inherited from java.awt.Component, it can be applied to all the classes that are inherited from the Component class...

Your Second question relates to using Dialogs. Since your question is not very specific. Here is an example of how to create a Dialog :

Dialog d=Dialog(Dialog owner, String title);
d.setSize(int Width,int Height);
d.setLocation(int Left,int Top);

If your new Big Idea doesn't scare the hell out of you, <br />it's probably not a "new Big Idea".
I agree. Here's the link:
subject: font size, and dialogbox
It's not a secret anymore!