Here's my code:
public class PaymentDialog {
public static int show(Double value) {
JLabel total = new JLabel("Total: ");
JLabel totalValue = new JLabel(value.toString());
JLabel input = new JLabel("Entrada: ");
JTextField inputField = new JTextField();
JLabel change = new JLabel("Troco: ");
JLabel changeValue = new JLabel("1234");
JComponent[] components = new JComponent[] {
total,
totalValue,
input,
inputField,
change,
changeValue
};
int result = JOptionPane.showConfirmDialog(null, components, "Pagamento", JOptionPane.OK_CANCEL_OPTION);
return result;
}
}
Here's an image of it:
As you can see, each component occupies an entire line, which is atrocious. The label should be behind it's corresponding component, instead of above it.
How do I customize this layout behavior? If it's impossible, how could I create a custom JDialog that allows me to do it? (Since I don't want to create a JFrame to customize the layout properly, as it's not the same thing).