本篇文章为大家展示了怎么在Java中利用Swing定制TextField功能,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
创新互联公司是一家专注于成都网站设计、成都做网站与策划设计,恩阳网站建设哪家好?创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:恩阳等地区。恩阳做网站价格咨询:13518219792具体代码如下:
package themedemo; import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.Insets; import java.awt.RenderingHints; import java.util.Map; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.Painter; import javax.swing.SwingUtilities; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.WindowConstants; public class TextFieldSkinDemo { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { for (UIManager.LookAndFeelInfo laf : UIManager .getInstalledLookAndFeels()) { if ("Nimbus".equals(laf.getName())) { try { UIManager.setLookAndFeel(laf.getClassName()); } catch (Exception e) { e.printStackTrace(); } } } for (Map.Entry<Object, Object> entry : UIManager .getLookAndFeelDefaults().entrySet()) { if ((entry.getKey().toString()).startsWith("TextField")) { System.out.println(entry.getKey() + " = " + entry.getValue()); } } JFrame frame = new JFrame("www.jb51.net - TextField Skining Demo"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BorderLayout()); JPanel panel = new JPanel(new GridLayout(0, 1, 20, 20)); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); panel.setBackground(Color.darkGray); UIDefaults textFieldDefaults = new UIDefaults(); textFieldDefaults.put("TextField.contentMargins", new Insets(6, 6, 6, 6)); textFieldDefaults.put("TextField[Selected].textForeground", Color.WHITE); textFieldDefaults.put("TextField.backgroundPainter", new Painter<JComponent>() { public void paint(Graphics2D g, JComponent c, int w, int h) { g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setStroke(new BasicStroke(2f)); g.setColor(Color.WHITE); g.fillRoundRect(0, 0, w - 2, h - 2, 8, 8); } }); textFieldDefaults.put("TextField.borderPainter", new Painter<JComponent>() { public void paint(Graphics2D g, JComponent c, int w, int h) { g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setStroke(new BasicStroke(2f)); g.setColor(Color.LIGHT_GRAY); g.drawRoundRect(0, 0, w - 2, h - 2, 8, 8); } }); JTextField textField = new JTextField(15); panel.add(textField); textField.putClientProperty("Nimbus.Overrides", textFieldDefaults); textField.putClientProperty("Nimbus.Overrides.InheritDefaults", false); // Add a normal themed slider for comparison JTextField normalTextField = new JTextField(15); panel.add(normalTextField); frame.getContentPane().add(panel, BorderLayout.CENTER); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } }
上述内容就是怎么在Java中利用Swing定制TextField功能,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
本文名称:怎么在Java中利用Swing定制TextField功能-创新互联
浏览路径:https://www.cdcxhl.com/article46/jgghg.html
成都网站建设公司_创新互联,为您提供网站策划、商城网站、域名注册、网站设计、面包屑导航、云服务器
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联