Results 1 to 8 of 8
Thread: Picture Alignment in JOptionPane
- 10-07-2012, 08:54 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
Picture Alignment in JOptionPane
I am making a dice game and am using pictures to display both the user's and the computer's dice roll, but I can't get the computer's dice picture to appear on the right side.

Here is my code:
Java Code:diceLabel.setIcon(new ImageIcon("<html><DIV align='right'>C:\\Users\\default.default-VAIO\\Downloads\\ Dice Game\\DiceFace" + compRoll + ".png</DIV></html>"));
- 10-07-2012, 09:23 PM #2
Re: Picture Alignment in JOptionPane
I haven't come across an ImageIcon constructor that takes a HTML String. Where did you get that code?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-07-2012, 09:33 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
Re: Picture Alignment in JOptionPane
I just wrote it up because I thought it might fit, since I had to use html code to do the breaks in the text.
- 10-07-2012, 09:40 PM #4
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
Re: Picture Alignment in JOptionPane
I got it to do this, but I want the computer's die to be on the right side of the text.
Attachment 4143
I used this code:
Java Code:if(compRoll > userRoll) { JLabel diceLabel = new JLabel("<html>Your roll: " + userRoll + "<br />Computer's Roll: " + compRoll + "<br />You lost to the computer.</html>"); ImageIcon icon = new ImageIcon("C:\\Users\\default.default-VAIO\\Downloads\\Dice Game\\DiceFace" + compRoll + ".png"); diceLabel = new JLabel("<html>Your roll: " + userRoll + "<br />Computer's Roll: " + compRoll + "<br />You lost to the computer.</html>", icon, JLabel.RIGHT); diceLabel.setIcon(new ImageIcon("C:\\Users\\default.default-VAIO\\Downloads\\Dice Game\\DiceFace" + userRoll + ".png")); JOptionPane.showMessageDialog(null, diceLabel, "Results", JOptionPane.INFORMATION_MESSAGE, icon); }
-
Re: Picture Alignment in JOptionPane
How about using the JLabel's API. There you'll find methods such as setHorizontalTextPosition(...) that can likely help you.
- 10-07-2012, 10:27 PM #6
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
Re: Picture Alignment in JOptionPane
I tried that, but the comp's image is staying right next to the user's image
- 10-07-2012, 10:59 PM #7
Member
- Join Date
- Oct 2012
- Posts
- 7
- Rep Power
- 0
- 10-08-2012, 04:10 AM #8
Re: Picture Alignment in JOptionPane
You can put 3 JLabels in a JPanel and pass that as the message argument, you know.
To get things where you want them to appear, see this Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
One picture for each texture, or all in one picture
By JG4m3r in forum AndroidReplies: 1Last Post: 05-24-2012, 04:44 PM -
GUI alignment
By africanhacker in forum New To JavaReplies: 5Last Post: 03-13-2011, 09:22 PM -
pls... help.... alignment....
By eiramae in forum Java AppletsReplies: 0Last Post: 02-26-2011, 06:47 AM -
Help with alignment
By firecat318 in forum AWT / SwingReplies: 3Last Post: 05-25-2010, 03:01 AM -
Label Alignment Example
By Java Tip in forum javax.swingReplies: 0Last Post: 06-27-2008, 07:49 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks