Swing Monospace-Schrift für alle Systeme

Jay1980

Bekanntes Mitglied
Servus,

ich habe eine JTextArea in einer JScrollpane, da lasse ich eine Texttabelle anzeigen, ähnlich eines Abfrageergebnisses in einer Konsole, wenn man das Konsolentool mysql nutzt.

Jetzt suche ich nach einer passenden Schrift, die auf allen Systemen (Linux, Windows und Mac) vorhanden ist und die Abstände sollen für alle Buchstaben identisch sein. Solche Schriften nennt man Monospace bzw. nichtproportionale Schrift.

Welche sind/ist da nun auf allen Systemen verfügbar ?
 
Hm, nun habe ich etwas probiert und gelesen und wenn ich es richtig verstanden habe, komme ich mit Courier bei Mac und Linux weit und mit Courier New bei Windows und Max OSX. Wie gehe ich nun geschickt vor, dass ich auf jedem System einem eine Monospaced-Schriftart erwische?

Aktuell sieht mein Font-Objekt der TextArea so aus:
Java:
font = new Font("Courier", Font.PLAIN, 14); // Linux und Mac koennen Courier, Windows und Mac OSX 'Courier New'
 
Ich glaube, Du hast den Beitrag von diggaa nicht richtig verstanden. Zur Erklärung; es gibt fünf "logische" Schriftarten die auf jedem System vorhanden sind. Welche physikalischen Schriftarten sich hinter den logischen verbergen, hängt vom System und ggf. dessen Konfiguration ab. Die API-Doc der [c]java.awt.Font[/c]-Klasse sagt dazu:
API-Doc hat gesagt.:
Physical and Logical Fonts
The Java Platform distinguishes between two kinds of fonts: physical fonts and logical fonts.

Physical fonts are the actual font libraries containing glyph data and tables to map from character sequences to glyph sequences, using a font technology such as TrueType or PostScript Type 1. All implementations of the Java Platform must support TrueType fonts; support for other font technologies is implementation dependent. Physical fonts may use names such as Helvetica, Palatino, HonMincho, or any number of other font names. Typically, each physical font supports only a limited set of writing systems, for example, only Latin characters or only Japanese and Basic Latin. The set of available physical fonts varies between configurations. Applications that require specific fonts can bundle them and instantiate them using the createFont method.

Logical fonts are the five font families defined by the Java platform which must be supported by any Java runtime environment: Serif, SansSerif, Monospaced, Dialog, and DialogInput. These logical fonts are not actual font libraries. Instead, the logical font names are mapped to physical fonts by the Java runtime environment. The mapping is implementation and usually locale dependent, so the look and the metrics provided by them vary. Typically, each logical font name maps to several physical fonts in order to cover a large range of characters.

Peered AWT components, such as Label and TextField, can only use logical fonts.
Du kannst also einfach so Deine nichtproportionale Schriftart laden: [c]new Font("Monospaced", Font.PLAIN, 14f);[/c]

Jetzt klarer?

Ebenius
 

Neue Themen


Zurück
Oben