Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-24-2008, 09:05 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
[SOLVED] Set Image
Hi all

How can i set image on the dialog..

i want to show image on the this.Plz help me

Code:
public class AboutDlg extends Dialog { private Button button; private Label label1; public AboutDlg(Frame parent) { super(parent,"About", false); setLayout(new BorderLayout(15,15)); setResizable(false); Font f; label1 = new Label("",Label.CENTER); } public boolean action (Event evt, Object arg) { if (evt.target instanceof Button) { hide(); dispose(); return true; } return false; } public boolean handleEvent (Event event) { switch (event.id) { case Event.WINDOW_DESTROY: dispose(); return true; default: return super.handleEvent(event); } } }

Last edited by Sarinam : 06-26-2008 at 07:01 AM. Reason: Solve
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-24-2008, 09:24 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You say that want to add an image to the background of a dialog?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-24-2008, 09:26 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
You say that want to add an image to the background of a dialog?
Yes ..

here i am useing label.seticon().But it is not working..

So plz help me
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-24-2008, 09:29 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Use an ImageIcon and add it to the label.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-24-2008, 09:41 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Use an ImageIcon and add it to the label.
i use ImageIcone but i am geting error

Code:
ImageIcon images; images = new ImageIcon("C:\\WINDOWS\\system32\\ntimage.gif"); label.add(images);
Here i am geting error in label5.add(images);.Showing red mark on .add.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-24-2008, 09:54 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Oops, you can't do this in AWT. It's valid for Swing only.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-24-2008, 10:00 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Oops, you can't do this in AWT. It's valid for Swing only.
i import swing package...Any way so how can i set image..
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 06-24-2008, 10:02 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Just importing the package not solve your question. Use a JLable instead a Label.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 06-24-2008, 10:08 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Just importing the package not solve your question. Use a JLable instead a Label.
Sir I was also use JLabel.But still error is same.I know package is not solution but i also use JLabel...
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 06-24-2008, 10:35 AM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Just importing the package not solve your question. Use a JLable instead a Label.
Hello Sir

So how can i get it sir
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 06-24-2008, 10:57 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Here is a simple example. You have to use AWT and Swing component in correct way.

Code:
import java.awt.*; import javax.swing.*; /** * * @author Eranga Tennakoon */ public class BackImage extends JFrame{ public BackImage() { JPanel framePanel = new JPanel(); setContentPane(framePanel); getContentPane().setLayout(new BorderLayout()); ImageIcon imageBack = new ImageIcon("images/master03_background.gif"); JLabel background = new JLabel(imageBack); background.setBounds(0, 0, imageBack.getIconWidth(), imageBack.getIconHeight()); getLayeredPane().add(background, new Integer(Integer.MIN_VALUE)); framePanel.setOpaque(false); setContentPane(framePanel); } public static void main(String[] args) { BackImage main = new BackImage(); main.setSize(100, 100); main.setVisible(true); } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 06-24-2008, 12:20 PM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Here is a simple example. You have to use AWT and Swing component in correct way.

Code:
import java.awt.*; import javax.swing.*; /** * * @author Eranga Tennakoon */ public class BackImage extends JFrame{ public BackImage() { JPanel framePanel = new JPanel(); setContentPane(framePanel); getContentPane().setLayout(new BorderLayout()); ImageIcon imageBack = new ImageIcon("images/master03_background.gif"); JLabel background = new JLabel(imageBack); background.setBounds(0, 0, imageBack.getIconWidth(), imageBack.getIconHeight()); getLayeredPane().add(background, new Integer(Integer.MIN_VALUE)); framePanel.setOpaque(false); setContentPane(framePanel); } public static void main(String[] args) { BackImage main = new BackImage(); main.setSize(100, 100); main.setVisible(true); } }

Thxs sir

Image is showing but not in poroper way.It is showing like a 3rd. here is code

Code:
public class AboutDlg extends JFrame { private Button button; private Label label1; private JLabel label2; private Label label3; private Label label4; private Label label5; public AboutDlg(Frame parent) { // super(parent,"About", false); JPanel framePanel = new JPanel(); setContentPane(framePanel); getContentPane().setLayout(new BorderLayout()); ImageIcon imageBack = new ImageIcon("C:\\WINDOWS\\Web\\hand2.gif"); JLabel background = new JLabel(imageBack); background.setBounds(0,0, imageBack.getIconWidth(), imageBack.getIconHeight()); getLayeredPane().add(background, new Integer(Integer.MAX_VALUE)); framePanel.setOpaque(false); setContentPane(framePanel); setLayout(new BorderLayout(15,15)); setResizable(false); Font f; label1 = new Label("",Label.CENTER); label2 = new JLabel("",JLabel.CENTER); label3 = new Label("",Label.CENTER); label4 = new Label("",Label.CENTER); label5 = new Label("",Label.CENTER); Panel lab = new Panel(); lab.setLayout(new GridLayout(5,3)); lab.add(label1); lab.add(label2); add("Center", lab); button = new Button("OK"); Panel p = new Panel(); p.setLayout(new FlowLayout(FlowLayout.CENTER,15, 15)); p.add(button); add("South", p); //f = new Font("Terminal", Font.BOLD, 15); //label1.setFont(f); //label1.setText("HTTP Proxy Server, Version 1.0"); //f = new Font("Terminal", Font.PLAIN, 13); pack(); Point fatherLocation = parent.location(); move(fatherLocation.x + 150,fatherLocation.y + 200); show(); } public boolean action (Event evt, Object arg) { if (evt.target instanceof Button) { hide(); dispose(); return true; } return false; } public boolean handleEvent (Event event) { switch (event.id) { case Event.WINDOW_DESTROY: dispose(); return true; default: return super.handleEvent(event); } } }
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 06-24-2008, 12:30 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Again you workout in wrong way with components. Reason is that you use three panels to add all those components. Do it using a one.

Panel is a container, holds components, in simple word. What you have done in your code is, one panel in the whole are, one in the center and the other is in south. So you can only see part of the larger panel, whole panel on the frame.

Hope it's clear.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 06-24-2008, 12:50 PM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Again you workout in wrong way with components. Reason is that you use three panels to add all those components. Do it using a one.

Panel is a container, holds components, in simple word. What you have done in your code is, one panel in the whole are, one in the center and the other is in south. So you can only see part of the larger panel, whole panel on the frame.

Hope it's clear.
It is showing but position is not good.Label is show on image..show how can i fixed it proper way.
Code:
public class AboutDlg extends JFrame { private Button button; private Label label1; private JLabel label2; private Label label3; private Label label4; private Label label5; public AboutDlg(Frame parent) { // super(parent,"About", false); JPanel framePanel = new JPanel(); setContentPane(framePanel); getContentPane().setLayout(new BorderLayout()); ImageIcon imageBack = new ImageIcon("C:\\WINDOWS\\Web\\exclam.gif"); JLabel background = new JLabel(imageBack); background.setBounds(0,0, imageBack.getIconWidth(), imageBack.getIconHeight()); getLayeredPane().add(background, new Integer(Integer.MAX_VALUE)); framePanel.setOpaque(false); setContentPane(framePanel); //setLayout(new BorderLayout(15,15)); setResizable(true); Font f; label1 = new Label("",Label.CENTER); label2 = new JLabel("",JLabel.CENTER); label3 = new Label("",Label.CENTER); label4 = new Label("",Label.CENTER); label5 = new Label("",Label.CENTER); // Panel lab = new Panel(); // framePanel.setLayout(new GridLayout(5,3)); framePanel.add(label1); framePanel.add(label2); // add("Center", lab); button = new Button("OK"); Panel p = new Panel(); framePanel.setLayout(new FlowLayout(FlowLayout.RIGHT,15, 15)); p.add(button); add("South",p); f = new Font("Terminal", Font.BOLD, 15); label1.setFont(f); label1.setText("HTTP Proxy Server, Version 1.0"); f = new Font("Terminal", Font.PLAIN, 13); pack(); Point fatherLocation = parent.location(); move(fatherLocation.x + 150,fatherLocation.y + 200); show(); } public boolean action (Event evt, Object arg) { if (evt.target instanceof Button) { hide(); dispose(); return true; } return false; } public boolean handleEvent (Event event) { switch (event.id) { case Event.WINDOW_DESTROY: dispose(); return true; default: return super.handleEvent(event); } } }
Help me sir
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 06-24-2008, 12:55 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have to think about layouts now. GridLayout and so on.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 06-24-2008, 01:13 PM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
You have to think about layouts now. GridLayout and so on.
i use
Code:
getContentPane().setLayout(new FlowLayout.CENTER,15,150); getContentPane().setLayout(new GridLayout(5,3)); getContentPane().setLayout(new BorderLayout(15,15));
And now tell me what i change here
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 06-24-2008, 01:22 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Use the GridLayout and add components in proper places. If you don't want to add anything, add an empty label. Set the transparent of the label too. If not you can't see the background image.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 06-24-2008, 01:42 PM
Senior Member
 
Join Date: Jun 2008
Posts: 121
Sarinam is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Use the GridLayout and add components in proper places. If you don't want to add anything, add an empty label. Set the transparent of the label too. If not you can't see the background image.
Sir Now i am geting .gif pic and label.But sir when i add more that one label and label.settext(""); writeing some text then label text showing in same line.

Plz help me
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 06-24-2008, 01:49 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have mess somewhere in the grid. I'll try to find it. But not now.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati