0

button name not clear

I am a beginner in Java and learning Java Swing.The text of the button when at runtime appears unreadable, as shown in the image https://i.stack.imgur.com/ihlQn.jpg . I have tried changing the font by the following lines of code. I worked on Windows 10 64-bit OS.

import javax.swing.*;
import java.awt.*;

public class Button1 {

    public static void main(String[] args) {
        Button1 gui = new Button1();
        gui.go();
    }

    public void go(){
        JFrame frame = new JFrame();
        JButton east = new JButton(" East");
        JButton west = new JButton(" West");
        JButton north = new JButton(" North");
        JButton south = new JButton(" South");
        JButton center = new JButton(" Center");

        frame.getContentPane(). add( BorderLayout.EAST, east);
        frame.getContentPane(). add( BorderLayout.WEST, west);
        frame.getContentPane(). add( BorderLayout.NORTH, north);
        frame.getContentPane(). add( BorderLayout.SOUTH, south);
        frame.getContentPane(). add( BorderLayout.CENTER, center);



        Font bigFont = new Font("serif", Font.BOLD , 10);
        east.setFont(bigFont);
        west.setFont(bigFont);
        north.setFont(bigFont);
        south.setFont(bigFont);
        center.setFont(bigFont);
        frame.setSize(300,300);
        frame.setVisible(true);
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    So when not setting the font, everything is okay? Try `new Font(`Font.SERIF, Font.BOLD , 10);`. (The difference is a capitalized "Serif".) – Joop Eggen Jan 21 '20 at 15:19
  • Probably your serif font is broken. I've started your example and all works fine. – Sergiy Medvynskyy Jan 21 '20 at 15:22
  • And what about if you don't set the font? Is it correct then? – Jean-Baptiste Yunès Jan 21 '20 at 15:28
  • Check out: https://stackoverflow.com/a/36632974/131872 for a short programs that lists the fonts on your machine to see if "serif" is supported. Note, on my machine it shows "Serif". Don't know if the upper case if important. – camickr Jan 21 '20 at 15:48

1 Answers1

0

Your code works correctly on my machine.

I'm going to hazard a guess that the problem is the font. Your OS may not understand it, and thus it is rendered as it is in your screenshot. I would try out a few other fonts, or check to see what fonts are available on your machine.