Page 1 of 3 123 LastLast
Results 1 to 20 of 50
  1. #1
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default [SOLVED] Set Image

    Hi all

    How can i set image on the dialog..

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

    Java 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

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Use an ImageIcon and add it to the label.
    i use ImageIcone but i am geting error

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

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  7. #7
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

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

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  9. #9
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

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

  10. #10
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Here is a simple example. You have to use AWT and Swing component in correct way.

    Java 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);
        }
    
    }

  12. #12
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Here is a simple example. You have to use AWT and Swing component in correct way.

    Java 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

    Java 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);
    		}
    	}
    
    
    
    
    }

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  14. #14
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

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

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  16. #16
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    You have to think about layouts now. GridLayout and so on.
    i use
    Java 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

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  18. #18
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    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

  19. #19
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  20. #20
    Sarinam is offline Senior Member
    Join Date
    Jun 2008
    Posts
    121
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    You have mess somewhere in the grid. I'll try to find it. But not now. :)
    Ok sir i am try to fiend it but not geting..

Page 1 of 3 123 LastLast

Similar Threads

  1. Add an image to JFrame
    By Eranga in forum AWT / Swing
    Replies: 4
    Last Post: 02-01-2010, 04:09 PM
  2. Image Verification
    By peiceonly in forum Java Servlet
    Replies: 2
    Last Post: 04-04-2009, 08:38 AM
  3. How to display image ?
    By Birkoff in forum AWT / Swing
    Replies: 7
    Last Post: 06-09-2008, 08:58 AM
  4. Replies: 0
    Last Post: 01-08-2008, 06:29 PM
  5. 2D Array to image
    By fred in forum Java 2D
    Replies: 1
    Last Post: 07-24-2007, 02:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •