Align text to the right in JOptionPane

跟風遠走 提交于 2019-12-04 05:28:54

问题


Is it possible to align the text to the right in JOptionPane? (I don't want to use JDialog) because I want to write some sentences in Arabic


回答1:


Create a JPanel, align your text in your JPanel and then add the JPanel as the Object parameter of the JOptionPane. Or use a JDialog (why the desire not to use one of these?).




回答2:


 String message = "<html><body><div width='200px' align='right'>This is some text!</div></body></html>";
 JLabel messageLabel = new JLabel(message);
 JOptionPane.showConfirmDialog(null, messageLabel);



回答3:


Try using a JLabel on the JOptionPane and then use HTML to align it.

You can find more about using HTML with Swing components here

Hope this helps.




回答4:


As stated by ... Hovercraft Full Of Eels, you perfectly can use a JComponent as message in a JOptionPane#showMessageDialog. As a consequence, create a JPanel using a GridBagLayout, put a JLabel in it with your text, use the righ set of GridBagConstraints to ensure the text is right-align, and voila ! A JOptionPane with a right-aligned text.



来源:https://stackoverflow.com/questions/6454887/align-text-to-the-right-in-joptionpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!