Background image in JOptionPane kow to?

O

Osiaq

Hi experts! Is it possible to set background image in
JOptionPane.showConfirmDialog ? Googling left and right brought me non-
working solutions only?
 
K

Knute Johnson

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());
}
});
}
}
 
K

Knute Johnson

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?
 
M

markspace

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.
 
K

Knute Johnson

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.
 
K

Knute Johnson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top