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 1 of 1

Thread: how to modify a JList Frame?

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

    Question how to modify a JList Frame?

    here is a code for a JList...my problem now is how to modify it by adding an image on it...three images at the bottom one at the left,center and at the right side of the frame...if anyone knows about this, please...help me...this will be used tomorrow for our examination....pls...i have tried adding a picture but it doesn’t work…and also, how can I change font size, style and color of the caption”My Picture Profile”?please…I’m begging you help…..

    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.ImageIcon;
    import javax.swing.SwingConstants;
    import java.awt.FlowLayout;
    import javax.swing.border.*;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
     
     
    public class finalexam extends JFrame{
     
        private static final long serialVersionUID = 1L;
        private JList colorList;
        private final String colorNames[]={"PINK","BLUE","GREEN","YELLOW","GRAY"};
        private final Color colors[]={Color.pink,Color.blue,Color.green,Color.yellow,Color.GRAY};
        private EtchedBorder eb= new EtchedBorder(1, Color.black, Color.gray);
     
        public finalexam(){
            super("MY PICTURE PROFILE");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(500, 500);
            setLayout(new FlowLayout());
     
            colorList = new JList(colorNames);
            colorList.setSelectionMode(0);
            colorList.setBorder(eb);
     
            add(new JScrollPane(colorList));
     
            colorList.addListSelectionListener(new ListSelectionListener() {
     
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    getContentPane().setBackground(colors[colorList.getSelectedIndex()]);
                }
            });
     
            add(colorList);
            setVisible(true);
        }
     
    JFrame myWindow=new JFrame();
    		myWindow.setSize(WIDTH,HEIGHT);
    		myWindow.getContentPane().setLayout(null);
    		JLabel myLabel=new JLabel("MY PICTURE GALLERY");
                    myLabel.setIcon(new ImageIcon("winter.jpg"));
    		myLabel.setHorizontalTextPosition(SwingConstants.LEFT);
    		myLabel.setBounds(450,10,350,20);
    		myWindow.getContentPane().add(myLabel);
    		myWindow.setVisible(true);
     
     
        public static void main(String args[]){
            new ListFrame();
        }
    }
    Last edited by helloworld922; October 15th, 2009 at 01:37 AM.


Similar Threads

  1. The Frame to be Center Position
    By r12ki in forum AWT / Java Swing
    Replies: 3
    Last Post: October 1st, 2009, 10:36 AM
  2. Replies: 5
    Last Post: September 19th, 2009, 06:48 AM
  3. [SOLVED] JAVA JList Problem in visual images
    By antitru5t in forum AWT / Java Swing
    Replies: 4
    Last Post: April 15th, 2009, 03:09 PM
  4. Replies: 1
    Last Post: March 31st, 2009, 02:49 PM
  5. Dropping to graphic element dragged from JList
    By tua1 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 29th, 2008, 07:22 AM

Tags for this Thread