Removing three dots "..." from JButton?

Hey, I am creating a calculator program with small buttons, I want one of the buttons to have β€œAns” on them, but whenever I make JButton less than 50, 50, it will show three dots. "...", how can I remove these points and show normal text?

+7
source share
5 answers

Perhaps this is due to the fact that the edge of your button is too large.

Try the following:

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

You can also disable the border:

 button.setBorder(null); 
+18
source

Do not set your preferred button size. Use your preferred button size and give the layout manager the layout of the components. The preferred size ensures that the text will display correctly in different Look and Feels modes.

+3
source

This code is trying to explain why layouts and preferred sizes are so important. The important part is input / output.

TestGuiSize.java

 import java.awt.*; import javax.swing.*; class TestGuiSize { public static void addButtonToPanel(JPanel panel, String label) { JButton button = new JButton(label); button.setMargin(new Insets(1,1,1,1)); panel.add(button); } public static void main(String[] args) { JPanel p = new JPanel(new GridLayout(4,3,3,3)); addButtonToPanel(p, "7"); addButtonToPanel(p, "8"); addButtonToPanel(p, "9"); addButtonToPanel(p, "/"); addButtonToPanel(p, "4"); addButtonToPanel(p, "5"); addButtonToPanel(p, "6"); addButtonToPanel(p, "*"); addButtonToPanel(p, "1"); addButtonToPanel(p, "2"); addButtonToPanel(p, "3"); addButtonToPanel(p, "-"); addButtonToPanel(p, "0"); p.add(new JLabel("")); addButtonToPanel(p, "Del"); addButtonToPanel(p, "+"); Dimension d = p.getPreferredSize(); System.out.println( "Preferred Size: " + d.getWidth() + "x" + d.getHeight()); JOptionPane.showMessageDialog(null, p); } } 

Enter exit

 prompt> java TestGuiSize Preferred Size: 113.0x105.0 prompt>java -Dswing.plaf.metal.controlFont=Dialog-22 TestGuiSize Preferred Size: 169.0x157.0 prompt>java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel TestGuiSize Preferred Size: 93.0x93.0 prompt>java -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel TestGuiSize Preferred Size: 205.0x129.0 prompt> 

Runtime options are just the tip of the iceberg of differences between runs that can break application GUI code. Layouts are designed to handle such differences.

+1
source

You can change the font size on the button. See the following links:

Font size setting

Increase font size (can be easily changed to reduce font size)

0
source

Use setMargin(Insets m) to adjust the space between the JButton border and the label. The default is (2, 14, 2, 14) . To make the most of the space for the label (and completely remove the dots), you can use something like

 myButton.setFont(new Font("Tahoma", Font.BOLD, 11)); myButton.setMargin(new Insets(0, -1, 0, -20)); myButton.setHorizontalAlignment(SwingConstants.LEFT); 
0
source

All Articles