public class Font extends Object
Fonts have a name, such as "Helvetica", a style and a point size (usually around 10). It's important to note that many devices have an extremely limited number of fonts. For example, most PalmPilot devices have only two fonts: plain and bold. If the font specified can't be found during drawing, the closest matching font will be used.
Here is an example showing text being drawn in a given font:
... Font font = new Font("Helvetica", Font.BOLD, 10); } public void onPaint(Graphics g) { g.setFont(font); g.drawText("Hello", 10, 10); ...
Modifier and Type | Field and Description |
---|---|
static int |
BOLD
A bold font style.
|
protected static double |
fontScale |
static int |
ITALIC
An italic font style.
|
static int |
OUTLINE
An outlined font style.
|
static int |
PLAIN
A plain font style.
|
static int |
STRIKETHROUGH
A strikethrough font style.
|
static int |
SUBSCRIPT
A subscript font style.
|
static int |
SUPERSCRIPT
A superscript font style.
|
static int |
SYSTEM_FONT_DEFAULT
For use with getSystemFont()
|
static int |
SYSTEM_FONT_GUI |
static int |
SYSTEM_FONT_MONOSPACED |
static int |
SYSTEM_FONT_SANS_SERIF |
static int |
SYSTEM_FONT_SERIF |
static int |
UNDERLINE
An underlined font style.
|
Constructor and Description |
---|
Font(String name,
int style,
int size)
Creates a font of the given name, style and size.
|
Modifier and Type | Method and Description |
---|---|
protected java.awt.Font |
_getAWTFont() |
Font |
change(FontChange fc)
Return a new Font with the specified changes applied.
|
Font |
changeNameAndSize(String newName,
int newSize)
Change the name and/or size of a Font.
|
Font |
changeStyle(int newStyle)
Return a new Font with the same name and size, but a different style.
|
boolean |
equals(Object obj)
Returns if this object is considered equal to the other object.
|
String |
getName()
Returns the name of the font.
|
int |
getSize()
Returns the size of the font.
|
int |
getStyle()
Returns the style of the font.
|
static Font |
getSystemFont(int which) |
int |
hashCode()
Returns a hashCode for the object.
|
boolean |
isSame(Font f)
Return if this Font is the same as another.
|
static String[] |
listFonts(ISurface s) |
String |
toString()
Return a String representation of this object.
|
public static final int PLAIN
public static final int BOLD
public static final int ITALIC
public static final int UNDERLINE
public static final int OUTLINE
public static final int STRIKETHROUGH
public static final int SUPERSCRIPT
public static final int SUBSCRIPT
protected static double fontScale
public static final int SYSTEM_FONT_DEFAULT
public static final int SYSTEM_FONT_GUI
public static final int SYSTEM_FONT_MONOSPACED
public static final int SYSTEM_FONT_SERIF
public static final int SYSTEM_FONT_SANS_SERIF
protected java.awt.Font _getAWTFont()
public String getName()
public int getSize()
public int getStyle()
public Font changeStyle(int newStyle)
newStyle
- The new style for the Font.public Font changeNameAndSize(String newName, int newSize)
newName
- The newName for the Font. If it is null the old name is used.newSize
- The newSize for the Font. If it is <= 0, the old size is used.public String toString()
Object
public int hashCode()
Object
public boolean isSame(Font f)
f
- another Font.public boolean equals(Object obj)
Object
public static Font getSystemFont(int which)
public Font change(FontChange fc)
fc
- a FontChange object.