Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you actually want smooth (non-aliased) text, <a href="http://download.oracle.com/javase/6/docs/api/java/awt/font/TextLayout.html" rel="nofollow noreferrer"><code>TextLayout</code></a> may make this easier. The <a href="http://download.oracle.com/javase/6/docs/api/java/awt/font/FontRenderContext.html" rel="nofollow noreferrer"><code>FontRenderContext</code></a> constructor can manage the anti-aliasing and fractional metrics settings.</p> <p>Addendum: Using <code>g2d.setColor(Color.blue)</code> seems to produce the expected effect.</p> <p>Addendum: On Mac OS X, the <code>Pixie</code> application in <code>/Developer/Applications/Graphics Tools/</code> is convenient for examining the anti-alias pixels. On other platforms, <a href="https://stackoverflow.com/questions/3742841"><code>Zoom</code></a> may be used.</p> <p><img src="https://i.stack.imgur.com/xgDHW.png" alt="alt text"></p> <pre><code>/** @see https://stackoverflow.com/questions/4285464 */ public class BITest extends JPanel { private BufferedImage image = createNameOnButton("Sample"); public BITest() { this.setPreferredSize(new Dimension( image.getWidth(), image.getHeight())); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(image, 0, 0, null); } public BufferedImage createNameOnButton(String label) { Font font = new Font("Arial", Font.PLAIN, 64); FontRenderContext frc = new FontRenderContext(null, true, true); TextLayout layout = new TextLayout(label, font, frc); Rectangle r = layout.getPixelBounds(null, 0, 0); System.out.println(r); BufferedImage bi = new BufferedImage( r.width + 1, r.height + 1, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = (Graphics2D) bi.getGraphics(); g2d.setColor(Color.blue); layout.draw(g2d, 0, -r.y); g2d.dispose(); return bi; } private void display() { JFrame f = new JFrame("BITest"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setUndecorated(true); f.add(this); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { new BITest().display(); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload