Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: java swing help

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question java swing help

    hi...need some info and anyone to help me in this problem.we are told to make a a picture gallery using java swing.we don't even discussed about this, we are only told to do some research...i have here codes that starts my work...i just copied it here because i don't know how to attach my codes here...

    import javax.swing.*;
     
    public class finMao2
     
    {
    	public static final int WIDTH=1000;
    	public static final int HEIGHT=680;
     
    	public static void main(String[]args)
    	{
    		JFrame myWindow=new JFrame();
    		myWindow.setSize(WIDTH,HEIGHT);
    		JLabel myLabel=new JLabel("My Picture Gallery");
    		myWindow.getContentPane().add(myLabel);
    		myWindow.setVisible(true);
    		}
    }

    this is only the initial codes for the program...the proble is...the "My Gallery" title is in the lower left side...i want to put it in top center...and another is how to add image on this gallery?pls...post some help regarding this...as i said i am a fresh java student...hope u'll understand.

    hoping for a positive response...
    Last edited by Freaky Chris; October 5th, 2009 at 02:13 AM.


  2. #2
    Junior Member
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java swing help

    Dunno about adding the image, but I think this might help your location problem:

    Do search for SpringLayout

    Java Platform SE 6

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: java swing help

    To add an image to a swing component simply create a new label without any text and use setIcon(Icon) to set its icon.

  4. #4
    Member
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java swing help

    Try this,

    import javax.swing.*;
    import javax.swing.ImageIcon;
    import javax.swing.SwingConstants;
     
    public class sample
    {
    	public static final int WIDTH=1000;
    	public static final int HEIGHT=680;
     
    	public static void main(String[]args)
    	{
    		JFrame myWindow=new JFrame();
    		myWindow.setSize(WIDTH,HEIGHT);
    		myWindow.getContentPane().setLayout(null);
    		JLabel myLabel=new JLabel("MY PICTURE GALLERY");
                    myLabel.setIcon(new ImageIcon("c:/help_icon.PNG"));
    		myLabel.setHorizontalTextPosition(SwingConstants.LEFT);//To change the text positon
    		myLabel.setBounds(450,10,350,20);//Setting Bounds
    		myWindow.getContentPane().add(myLabel);
    		myWindow.setVisible(true);
    		}
    }
    Last edited by Freaky Chris; October 7th, 2009 at 11:39 AM.

Similar Threads

  1. How to Add ActionListener to a JButton in Swing?
    By JavaPF in forum Java Swing Tutorials
    Replies: 17
    Last Post: April 24th, 2013, 05:14 PM
  2. Java program to Add a JMenu toolbar to a Java Swing application
    By JavaPF in forum Java Swing Tutorials
    Replies: 6
    Last Post: March 6th, 2012, 12:25 PM
  3. How to Use a JSlider - Java Swing
    By neo_2010 in forum Java Swing Tutorials
    Replies: 4
    Last Post: March 29th, 2010, 09:33 AM
  4. Help - Swing Timer, 2 KeyEvents
    By Gheta in forum AWT / Java Swing
    Replies: 2
    Last Post: July 29th, 2009, 02:46 PM
  5. How to Use the JList component - Java Swing
    By neo_2010 in forum Java Swing Tutorials
    Replies: 1
    Last Post: July 11th, 2009, 04:02 AM

Tags for this Thread