2009-12-27 28 views

Respuesta

10

Uso UIManager para definir la fuente predeterminada de JLabel:

import java.awt.FlowLayout; 
import java.awt.Font; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.UIManager; 

public class LabelFont { 

    public static void main(String[] args) { 
     Font oldLabelFont = UIManager.getFont("Label.font"); 
     UIManager.put("Label.font", oldLabelFont.deriveFont(Font.PLAIN)); 

     JFrame f = new JFrame("LabelFont Test"); 
     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     f.getContentPane().setLayout(new FlowLayout()); 

     JLabel df = new JLabel("Default JLabel font"); 
     f.getContentPane().add(df); 

     JLabel ef = new JLabel("Font explicitly set"); 
     ef.setFont(oldLabelFont); 
     f.getContentPane().add(ef); 

     f.pack(); 
     f.setVisible(true); 
    } 
} 

Vía: http://coding.derkeiler.com/Archive/Java/comp.lang.java.help/2005-04/msg00395.html

+0

estoy confundido un poco. Traté de seguir el mismo procedimiento que todos ustedes haciendo. Usando UIManager y luego poniendo nuevas propiedades JLabel.font con otro tipo de fuente, pero parece no afectado en mi pc. ¿Hay algún problema con este UIManager? :) – gumuruh

2

¿Esto es lo que estás buscando?

import java.awt.FlowLayout; 
import java.awt.Font; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.UIManager; 

public class LabelFont { 

    public static void main(String[] args) { 
     Font oldLabelFont = UIManager.getFont("Label.font"); 
     UIManager.put("Label.font", oldLabelFont.deriveFont(Font.PLAIN)); 

     JFrame f = new JFrame("LabelFont Test"); 
     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     f.getContentPane().setLayout(new FlowLayout()); 

     JLabel df = new JLabel("Default JLabel font"); 
     f.getContentPane().add(df); 

     JLabel ef = new JLabel("Font explicitly set"); 
     ef.setFont(oldLabelFont); 
     f.getContentPane().add(ef); 

     f.pack(); 
     f.setVisible(true); 
    } 
} 
Cuestiones relacionadas