Setting 1 or 2 character text on a 32x32 JButton

I want to set text on a 32x32 JButton but it only shows "...". yes i know you can see the text if you make the button bigger, but how can you show the text on a 32x32 jbutton? The text has only 1 or 2 numbers (symbols), it is actually a counter. Thanks to

+3


source to share


3 answers


Insertion is probably displacing text ...

try

button.setMargin(new Insets(1, 1, 1, 1));  

      



edit: also use a smaller font.

edit2: you can also control inserts for all buttons:

UIManager.put("Button.margin", new Insets(1, 1, 1, 1));

      

+3


source


I don't think this is possible, it is managed directly with the look'n'feel that Java uses. You can try changing it to something else to see if it has different inserts. You can try changing them by programming smaller insects.



A more complicated way would be to subclass the class JButton

and provide a custom blueprint implementation, but I think you will lose all the other cool effects.

+1


source


As per my idea , its quite simple to making GUI application  easier.I am writing some code below it may help you .

public static void main(String[] args) {
        // TODO Auto-generated method stub
            JFrame frm=new JFrame("Manoj Button Test");
            frm.setVisible(true);
            frm.setSize(500,500);
            Container cnt=frm.getContentPane();
                        //You can add any text to the JButton
            JButton btn=new JButton("Hello Button");
            cnt.add(btn);           

            //2nd type of example 
            JButton btn2=new JButton();
            int number_btntext=4;
            btn2.setText(String.valueOf(number_btntext));
            cnt.add(btn2);


    }


In the above code I have set text to GUI JButton.

      

0


source







All Articles