Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Change the Font in a JLabel  (Read 1760 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« on: August 27, 2007, 06:35:26 AM »

Code
GeSHi (java):
  1. import java.awt.Container;
  2. import java.awt.FlowLayout;
  3. import java.awt.Font;
  4. import java.awt.GridLayout;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JLabel;
  8.  
  9. /*--------------------------------------------------------------------------
  10. //Author List:
  11. //   deAppel <Creator>
  12. //
  13. //Description:
  14. // Example of changing the FONT or a String in a JLabel by using the Swing GUI.
  15. //
  16. //Environment:
  17. //   This software was developed using Eclipse and Java 1.6
  18. //
  19. //Copyright Information:
  20. //   Copyright (C) 2007      <Institution><None>
  21. // Ark de Appel www.engineeringserver.com
  22. //
  23. //----------------------------------------------------------------------*/
  24. public class FontDemo extends JFrame{
  25. JLabel text1, text2, text3;
  26.  
  27.  
  28. public FontDemo(){
  29. Container c = getContentPane();
  30. c.setLayout(new GridLayout(3,1)); //3 down, 1 right
  31.  
  32. text1 =  new JLabel("Java default Font");
  33. c.add(text1);
  34.  
  35. text2 =  new JLabel("Java SansSerif Font BOLD");
  36. Font f1 = new Font("SansSerif", Font.BOLD, 12);
  37. text2.setFont(f1);
  38. c.add(text2);
  39.  
  40. text3 =  new JLabel("Java serif Font ITALIC");
  41. Font f2 = new Font("serif", Font.ITALIC, 12);
  42. text3.setFont(f2);
  43. c.add(text3);
  44.  
  45.  
  46. pack();
  47. setTitle("FontDemo");
  48. setLocationRelativeTo(null);
  49. setResizable(false);
  50. setVisible(true);
  51. }
  52.  
  53. public static void main(String[] args){
  54. FontDemo FD = new FontDemo();
  55.  
  56. }
  57. }
  58.  
Created by GeSHI 1.0.7.20

Sceenshot:
http://img174.imageshack.us/img174/9357/fontpf1.png
Change the Font in a JLabel

« Last Edit: August 27, 2007, 06:38:29 AM by HappyFace » Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here