gpt4 book ai didi

java - 在 JOptionPane 中对齐文本

转载 作者:行者123 更新时间:2023-12-01 19:52:40 24 4
gpt4 key购买 nike

我有以下代码行

JOptionPane.showMessageDialog(rootPane, "Código incorreto\nPor favor verifique", "Atenção", JOptionPane.ERROR_MESSAGE);

此处显示此消息

enter image description here

如何将这两行文本置于框的中心?

最佳答案

JLabel label = new JLabel("<html><center>Código incorreto<br>Por favor verifique");
label.setHorizontalAlignment(SwingConstants.CENTER);
JOptionPane.showMessageDialog(null, label, "Atenção", JOptionPane.ERROR_MESSAGE);

试试这个。预览:

enter image description here

关于java - 在 JOptionPane 中对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50786615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com