I have a jbutton in a Jpanel which has FlowLayout with trailing alignment. This code actually works in ubuntu environment but when i run it in the centos enviornment, text does not fit on the button.
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
myButton = new JButton("My Text");
buttonPanel.add(myButton);
Then I add the following lines:
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
myButton = new JButton("My Text");
int width=myButton.getFontMetrics(exportButton.getFont()).stringWidth(myButton.getText());
int height=myButton.getFontMetrics(myButton.getFont()).getHeight()+10;
myButton.setPreferredSize(new Dimension(width+30, height));
buttonPanel.add(myButton);
This additional lines helped but it seems, the solution is not good.