|
|
Background image in JOptionPane kow to?
Hi experts! Is it possible to set background image in
JOptionPane.showConfirmDialog ? Googling left and right brought me non-
working solutions only?
|
|
0
|
|
|
|
Reply
|
Osiaq
|
12/3/2010 10:32:25 AM |
|
On 12/3/2010 2:32 AM, Osiaq wrote:
> Hi experts! Is it possible to set background image in
> JOptionPane.showConfirmDialog ? Googling left and right brought me non-
> working solutions only?
There is more than one way to skin a cat.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
public class test6 extends JPanel {
private BufferedImage bi;
public test6() {
try {
bi = ImageIO.read(
new URL("http://rabbitbrush.frazmtn.com/kittens.jpg"));
setPreferredSize(
new Dimension(bi.getWidth(),bi.getHeight()));
} catch (IOException ioe) {
}
}
public void paintComponent(Graphics g) {
g.drawImage(bi,0,0,null);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JOptionPane pane = new JOptionPane(new test6(),
JOptionPane.INFORMATION_MESSAGE,
JOptionPane.YES_NO_OPTION);
JDialog dialog = pane.createDialog(null,"Title");
dialog.setVisible(true);
dialog.dispose();
System.out.println(pane.getValue());
}
});
}
}
--
Knute Johnson
email s/nospam/knute2010/
|
|
0
|
|
|
|
Reply
|
Knute
|
12/3/2010 6:01:35 PM
|
|
I have been trying to do the same thing, get a background imagine in my JOptionPane. This code works great but I am having trouble figuring out how to assign actions to the Yes and no buttons. Any help you be great?
|
|
0
|
|
|
|
Reply
|
jjd14rules (2)
|
12/3/2010 8:57:48 PM
|
|
On 12/3/2010 12:57 PM, jjd14rules wrote:
> I have been trying to do the same thing, get a background imagine in
> my JOptionPane. This code works great but I am having trouble
> figuring out how to assign actions to the Yes and no buttons. Any
> help you be great?
Do you mean Action or how to branch code depending on which button is
pressed?
--
Knute Johnson
email s/nospam/knute2010/
|
|
0
|
|
|
|
Reply
|
Knute
|
12/3/2010 9:33:27 PM
|
|
How to branch the code based on which button is pressed. Originally I made my JOptionPane.showConfirmDialog an int called reply which allowed me to use if statements to see if reply equaled the yes or the no option.
|
|
0
|
|
|
|
Reply
|
jjd14rules (2)
|
12/4/2010 7:17:20 PM
|
|
On 12/4/2010 11:17 AM, jjd14rules wrote:
> How to branch the code based on which button is pressed. Originally I
> made my JOptionPane.showConfirmDialog an int called reply which
> allowed me to use if statements to see if reply equaled the yes or
> the no option.
Knute seems to do the same thing here:
System.out.println(pane.getValue());
There's a bit of discussion on the JOptionPane on the tutorial page:
<http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html#features>
But the Java docs seem to have more:
<http://download.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html#getValue()>
Don't ignore the fields defined at the beginning of that page.
|
|
0
|
|
|
|
Reply
|
markspace
|
12/4/2010 8:34:40 PM
|
|
On 12/04/2010 12:34 PM, markspace wrote:
> On 12/4/2010 11:17 AM, jjd14rules wrote:
>> How to branch the code based on which button is pressed. Originally I
>> made my JOptionPane.showConfirmDialog an int called reply which
>> allowed me to use if statements to see if reply equaled the yes or
>> the no option.
>
> Knute seems to do the same thing here:
>
> System.out.println(pane.getValue());
>
> There's a bit of discussion on the JOptionPane on the tutorial page:
>
> <http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html#features>
>
>
> But the Java docs seem to have more:
>
> <http://download.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html#getValue()>
>
>
> Don't ignore the fields defined at the beginning of that page.
>
markspace gave you some great resources. If you need any more help feel
free to post some more.
--
Knute Johnson
s/nospam/knute2010/
|
|
0
|
|
|
|
Reply
|
Knute
|
12/5/2010 2:59:57 AM
|
|
On 12/04/2010 12:34 PM, markspace wrote:
> On 12/4/2010 11:17 AM, jjd14rules wrote:
>> How to branch the code based on which button is pressed. Originally I
>> made my JOptionPane.showConfirmDialog an int called reply which
>> allowed me to use if statements to see if reply equaled the yes or
>> the no option.
>
> Knute seems to do the same thing here:
>
> System.out.println(pane.getValue());
>
> There's a bit of discussion on the JOptionPane on the tutorial page:
>
> <http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html#features>
>
>
> But the Java docs seem to have more:
>
> <http://download.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html#getValue()>
>
>
> Don't ignore the fields defined at the beginning of that page.
>
markspace gave you some great resources. If you need any more help feel
free to post some more.
--
Knute Johnson
s/nospam/knute2010/
|
|
0
|
|
|
|
Reply
|
Knute
|
12/5/2010 3:03:34 AM
|
|
|
9 Replies
1077 Views
(page loaded in 0.102 seconds)
|
|
|
|
|
|
|
|
|