List of usage examples for java.awt Font Font
private Font(String name, int style, float sizePts)
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2D;//from w ww .j a v a2 s . c o m g2D = (Graphics2D) g; FontRenderContext frc = g2D.getFontRenderContext(); Font font1 = new Font("Courier", Font.BOLD, 24); String str1 = new String("Java"); TextLayout tl = new TextLayout(str1, font1, frc); g2D.setColor(Color.gray); tl.draw(g2D, 70, 150); }
From source file:IteratorUnderStrike.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; String s = "\"www.java2s.com\" is great."; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font plainFont = new Font("Times New Roman", Font.PLAIN, 24); AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, plainFont); as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 15); as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 18, 25); g2.drawString(as.getIterator(), 24, 70); }
From source file:BasicShapes.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; int x = 10, y = 10, start = 2, end = 4; AttributedString astr = new AttributedString("aString"); astr.addAttribute(TextAttribute.FONT, new Font("", 1, 1), start, end); astr.addAttribute(TextAttribute.BACKGROUND, Color.red, start, end); // Draw mixed-style text TextLayout tl = new TextLayout(astr.getIterator(), g2d.getFontRenderContext()); tl.draw(g2d, x, y);//from www . ja va2s. c o m }
From source file:JTextAreaDemo.java
public JTextAreaDemo() { super("JTextAreaDemo"); GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = new Font("LucidaSans", Font.PLAIN, 40); JTextArea textArea = new JTextArea(davidMessage + andyMessage); textArea.setFont(font);/* w ww . j a v a2 s .c om*/ this.getContentPane().add(textArea); textArea.show(); }
From source file:Main.java
public Main() { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(); DecimalFormatSymbols dfs = df.getDecimalFormatSymbols(); dfs.setZeroDigit('\u0660'); df.setDecimalFormatSymbols(dfs);//from w ww. j av a 2s.co m JLabel label = new JLabel(df.format(1234567.89)); label.setFont(new Font("Lucida Sans", Font.PLAIN, 22)); add(label); }
From source file:Main.java
public Main() { setSize(300, 150);// w w w. j a v a 2 s. co m setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new FlowLayout()); add(b); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { b.setFont(new Font("Dialog", Font.PLAIN, ++size)); b.revalidate(); } }); setVisible(true); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = new Font("Serif", Font.PLAIN, 72); g2.setFont(font);/* www . j a v a2 s .c o m*/ String s = "this is a test"; float x = 50, y = 150; // Draw the baseline. FontRenderContext frc = g2.getFontRenderContext(); float width = (float) font.getStringBounds(s, frc).getWidth(); Line2D baseline = new Line2D.Float(x, y, x + width, y); g2.setPaint(Color.red); g2.draw(baseline); // Draw the ascent. LineMetrics lm = font.getLineMetrics(s, frc); Line2D ascent = new Line2D.Float(x, y - lm.getAscent(), x + width, y - lm.getAscent()); g2.draw(ascent); // Draw the descent. Line2D descent = new Line2D.Float(x, y + lm.getDescent(), x + width, y + lm.getDescent()); g2.draw(descent); // Draw the leading. Line2D leading = new Line2D.Float(x, y + lm.getDescent() + lm.getLeading(), x + width, y + lm.getDescent() + lm.getLeading()); g2.draw(leading); // Render the string. g2.setPaint(Color.black); g2.drawString(s, x, y); }
From source file:FontDerivation.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Create a 1-point font. Font font = new Font("Serif", Font.PLAIN, 1); float x = 20, y = 20; Font font24 = font.deriveFont(24.0f); g2.setFont(font24);//from w w w .ja v a2 s . c o m g2.drawString("font.deriveFont(24.0f)", x, y += 30); Font font24italic = font24.deriveFont(Font.ITALIC); g2.setFont(font24italic); g2.drawString("font24.deriveFont(Font.ITALIC)", x, y += 30); AffineTransform at = new AffineTransform(); at.shear(.2, 0); Font font24shear = font24.deriveFont(at); g2.setFont(font24shear); g2.drawString("font24.deriveFont(at)", x, y += 30); Hashtable attributes = new Hashtable(); attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); Font font24bold = font24.deriveFont(attributes); g2.setFont(font24bold); g2.drawString("font24.deriveFont(attributes)", x, y += 30); }
From source file:TexturedText.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = new Font("Times New Roman", Font.PLAIN, 72); g2.setFont(font);// www .ja v a 2s . c o m String s = "Java Source and Support"; Dimension d = getSize(); float x = 20, y = 100; BufferedImage bi = getTextureImage(); Rectangle r = new Rectangle(0, 0, bi.getWidth(), bi.getHeight()); TexturePaint tp = new TexturePaint(bi, r); g2.setPaint(tp); g2.drawString(s, x, y); }
From source file:Text.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh);/* ww w. jav a 2 s. co m*/ Font font = new Font("New Roma", Font.BOLD, 40); g2d.setFont(font); g2d.drawString("text", 20, 30); }