JButton.setText horizontal sliced

import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JFrame;


public class Example {

public static void main(String args[]){
    JFrame frame = new JFrame();
    frame.setResizable(false);
    frame.setMinimumSize(new Dimension(200,150));
    frame.setLocationRelativeTo(null);
    frame.setLayout(null);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton exampleBtn1 = new JButton("set");
    exampleBtn1.setBounds(10, 10, 70, 10);
    frame.add(exampleBtn1);

    JButton exampleBtn2 = new JButton("set");
    exampleBtn2.setBounds(10, 30, 50, 10);
    frame.add(exampleBtn2);
}
}

      

this code displays a JFrame with two JButtons, each showing the text "set" cut off slightly vertically. but I cannot get the same result horizontally and the JButtonBtn2 example is an example of my problem.

how to make exampleBtn2 able to show all text in horizontal orientation? I want to get the same result as vertical: even though the JButton is small enough to show all the text, I want to see it cut off, not repeating dots.

+3


source to share


2 answers


You may try:



exampleBtn2.setMargin(new Insets(0, 0, 0, 0));

      

+1


source


You can try a smaller FontSize with:



exampleBtn1.setFont(new Font("Arial", Font.PLAIN, 7));

      

0


source







All Articles