0

Here's the code:

JOptionPane pane = new JOptionPane(findArray, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION);
pane.setOptions(new Object[]{findPreviousButton, findNextButton});
final JDialog dialog = pane.createDialog(myJFrame, "Find");
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);

findArray consists of JLabel findLabel and JTextField findField. myJFrame is the JFrame. findPreviousButton and findNextButton are the two JButtons I am replacing the default "OK" and "Cancel" buttons with. The both have custom icons and no text. The JDialog window is making their icons a certain size making them look pixelated. How do I resize the buttons so that the width is 60 and the height is 30? The method .setSize(int, int) doesn't work and neither does .setBounds(int, int, int, int)

Scott
  • 3
  • 2
  • 1
    `The JDialog window is making their icons a certain size making them look pixelated.` - Works fine for me using JDK7 on Windows 7. The buttons are the size of the icons plus the standard button padding. – camickr Aug 07 '13 at 19:00
  • I'm sorry your right, I tried comparing them closer and they are the same size, the picture just is less quality :/ that's embarassing – Scott Aug 08 '13 at 02:09

2 Answers2

0

Adjusting the button margins should help: http://docs.oracle.com/javase/7/docs/api/javax/swing/AbstractButton.html#setMargin(java.awt.Insets)

0

You'll probably want to use .setPreferredSize() instead of .setSize(). Usually when I want to override a component's natural size (meaning how it's laid out by whatever layout manager I'm using), I'll use that along with setting the minimum size as well. If a layout manager is modifying the component's natural size, the preferredSize() might be a better option. There's a good stackoverflow discussion about the differences here:

Java: Difference between the setPreferredSize() and setSize() methods in components

Community
  • 1
  • 1
framauro13
  • 797
  • 2
  • 8
  • 18