In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how java modifies the default font of JFrame. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
Java modifies JFrame default font
The way to change the default font is simple. First of all, let's write a random button:
Import javax.swing.*; public class Test {static final int WIDTH = 300; static final int HEIGHT = 200; public static void main (String [] args) {JFrame jf = new JFrame (); jf.setVisible (true); jf.setSize (WIDTH,HEIGHT); jf.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); JPanel jp = new JPanel () Jf.setcontentPane (jp); JButton jb = new JButton ("OK"); jp.add (jb); jf.pack ();}}
Then we can add this line:
UIManager.put ("Button.font", new java.awt.Font ("Song style", 0,12))
Add the following import at the beginning:
Import javax.swing.UIManager
So you can change the font.
The font type and size can be changed freely, as long as it is installed in the computer. The "0" position represents the font style and is generally not modified. (such as italics, bold, etc., if you want to modify, please refer to API. I don't remember much either. )
It is not recommended to use personalized fonts on the Internet, because the software programs made in this way can cause font problems when used on other computers. And try to use as few obscure words as possible, lest some font libraries do not include corresponding glyphs.
Custom fonts can be encapsulated as follows: (the following section is excerpted from the network)
Public class FontClass {public static void loadIndyFont () {UIManager.put ("CheckBox.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("Tree.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("Viewport.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("ProgressBar.font", new java.awt.Font ("Song style", 0,12)) UIManager.put ("RadioButtonMenuItem.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("FormattedTextField.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("ToolBar.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("ColorChooser.font", new java.awt.Font ("Song style", 0,12)) UIManager.put ("ToggleButton.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("Panel.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("TextArea.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("Menu.font", new java.awt.Font ("Song style", 0,12)) UIManager.put ("RadioButtonMenuItem.acceleratorFont", new java.awt.Font ("Song style", 0,12); UIManager.put ("Spinner.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("Menu.acceleratorFont", new java.awt.Font ("Song style", 0,12)); UIManager.put ("CheckBoxMenuItem.acceleratorFont", new java.awt.Font ("Song style", 0,12)) UIManager.put ("TableHeader.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("TextField.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("OptionPane.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("MenuBar.font", new java.awt.Font ("Song style", 0,12)) UIManager.put ("Button.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("Label.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("PasswordField.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("InternalFrame.titleFont", new java.awt.Font ("Song style", 0,12)) UIManager.put ("OptionPane.buttonFont", new java.awt.Font ("Song style", 0,12); UIManager.put ("ScrollPane.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("MenuItem.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("ToolTip.font", new java.awt.Font ("Song style", 0,12)) UIManager.put ("List.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("OptionPane.messageFont", new java.awt.Font ("Song style", 0,12)); UIManager.put ("EditorPane.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("Table.font", new java.awt.Font ("Song style", 0,12)) UIManager.put ("TabbedPane.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("RadioButton.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("CheckBoxMenuItem.font", new java.awt.Font ("Song style", 0,12)); UIManager.put ("TextPane.font", new java.awt.Font ("Song style", 0,12)) UIManager.put ("PopupMenu.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("TitledBorder.font", new java.awt.Font ("Song style", 0,12); UIManager.put ("ComboBox.font", new java.awt.Font ("Song style", 0,12));}
Then we just need to add when we want to use it:
FontClass.loadIndyFont ()
That's all right.
JFrame basic parameter setting import java.io.IOException;import java.awt.Font;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import javax.swing.JFrame;import javax.swing.ImageIcon;import javax.swing.UIManager;import javax.imageio.ImageIO;public class Frame implements WindowListener {public static JFrame frame; public Frame () {initialize ();} private void initialize () {/ / New form frame = new JFrame () / / set form auto-resize frame.pack (); / / set form position and size frame.setBounds (100,100,100,100); / / set form resizable frame.setResizable (false); / / set form layout frame.getContentPane (). SetLayout (null) / / set the form title frame.setTitle ("Frame"); / / set the form font frame.setFont (new Font ("boldface", Font.PLAIN, 17); / / set the form to open frame.setLocationRelativeTo (null) in the middle of the screen; / / set the form to be closed by default to exit the program frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) / / set the form icon frame.setIconImage (ImageIO.read (this.getClass (). GetResource ("/ priv/image/image.png")); / / set the form look and feel (skin / theme) UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); / / set whether the form is visible frame.setVisible (true); / / add WindowListener frame.addWindowListener (this) } / * * @ description rewrite WindowListener * @ param e * / public void windowClosing (WindowEvent e) {} public void windowClosed (WindowEvent e) {} public void windowOpened (WindowEvent e) {} public void windowIconified (WindowEvent e) {} public void windowDeiconified (WindowEvent e) {} public void windowActivated (WindowEvent e) {} public void windowDeactivated (WindowEvent e) {} public static void main (String args []) {new Frame () }} above is all the content of the article "how to modify the default font mode of JFrame by java". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.