Image is covering all of JDialog!

I have my class extending JDialog.

I have setSize(300,300).

I have added some components like JLabel, JEditorPane etc in constructor method.

I have redefined paint(Graphics g) method in order to put image on JDialog.

Image is size 100,100 and it is shown but all the space on JDialog where isn't image is gray, every component that I have added in constructor is missing.

Why is this happening and how to solve it so that both image and components are shown?

[497 byte] By [BobMila] at [2007-11-26 15:49:47]
# 1
Let's make a deal: you send some code, we send some answers.
quittea at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 2
@Op. Do you call super.paint?
kajbja at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 3
And shouldn't the OP call paintComponent, instead of paint?~Tim
SomeoneElsea at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 4
> And shouldn't the OP call paintComponent, instead of> paint?> > ~TimCall? You mean override?
kajbja at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 5
Of course, you know what I mean, and pay no attention to what I say!Mea Culpa, I need more coffee, obviously!~Tim
SomeoneElsea at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 6

Here is the code:

import java.awt.*;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.*;

public class TestJDialog {

public static void main(String[] args){

Test te = new Test();

te.setVisible(true);

}

}

class Test extends JDialog {

Test(){

setSize(600,250);

setResizable(false);

setModal(true);

setLayout(null);

JTextArea jte = new JTextArea();

add(jte);

jte.setText("Some text Some text Some text");

jte.setLocation(130,10);

jte.setSize(jte.getPreferredSize());

jte.setBackground(this.getBackground());

jte.setEditable(false);

JLabel jlbWWW = new JLabel("WWW:");

jlbWWW.setSize(jlbWWW.getPreferredSize());

jlbWWW.setLocation(130,170);

JLabel jlbEMail = new JLabel("E-mail:");

jlbEMail.setSize(jlbEMail.getPreferredSize());

jlbEMail.setLocation(130,185);

add(jlbWWW);

add(jlbEMail);

}

public void paint(Graphics g){

try {

Image imgL = ImageIO.read(new FileInputStream("SomeImage.bmp"));

g.drawImage(imgL,0,0,this);

} catch (IOException e) {

}

}

}

BobMila at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 7
Ok, see replies #2 and #3/#5.1. Override paintComponent instead of paint2. Call the method implementation of the super class before starting to drawBtw.: creating the image within paint() or paintComponent() respectively is rather inefficient.
quittea at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 8

> Ok, see replies #2 and #3/#5.

>

> 1. Override paintComponent instead of paint

> 2. Call the method implementation of the super class

> before starting to draw

>

> Btw.: creating the image within paint() or

> paintComponent() respectively is rather inefficient.

1. I have renamend paint into paintComponents (you have write paintComponent), but then nothing happened, image isn't shown at all.

2. I don't understand what method to call?!

BobMila at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 9

You have been asked at least twice before to post Swing related questions in the Swing forum.

Three strikes and your out. Too bad really its a simple request that has been asked and answered dozens of times in the Swing forum. So all you really need to do is search the Swing forum for the answer.

camickra at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 10

> You have been asked at least twice before to post

> Swing related questions in the Swing forum.

>

> Three strikes and your out. Too bad really its a

> simple request that has been asked and answered

> dozens of times in the Swing forum. So all you really

> need to do is search the Swing forum for the answer.

My opinion is that this forum is for any kind of java question.

And beside that my question isn't strictly Swing related.

Nevermind that, I just want answer.

BobMila at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 11

> My opinion is that this forum is for any kind of java

> question.

And everyone else's opinion is that Swing questions should be posted in the Swing forum.

> And beside that my question isn't strictly Swing

> related.

Yes it is.

> Nevermind that, I just want answer.

Too bad.

CaptainMorgan08a at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 12

> > My opinion is that this forum is for any kind of

> java

> > question.

>

> And everyone else's opinion is that Swing

> questions should be posted in the Swing forum.

>

> > And beside that my question isn't strictly Swing

> > related.

>

> Yes it is.

>

> > Nevermind that, I just want answer.

>

> Too bad.

I don't give a **** what you think.

I will not answer to this stupid replies anymore, if someone can help me then please do so, if not don't reply. I didn't post question so I could argue to people on which forum to post it but to get an answer.

BobMila at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...
# 13

see the only way you can have image at the background and component on it,

is make the panel and the components which you added to the panel opaque(flase) and make this panel as the contentPane

then override the paint method of the JDialog to paint the image and do call super.paint(g).

kudikala_venua at 2007-7-8 22:09:27 > top of Java-index,Java Essentials,Java Programming...