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

Thread: Everything but JLabel is displaying

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Location
    Maine
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Everything but JLabel is displaying

    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import java.awt.Toolkit;
    import java.io.*;
     
    public class RunescapeApp {
            public static void main(String[] a) {
     
                    JFrame f = new JFrame();
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    f.add(new ButtonDemo());
                    f.setSize(550, 400);
                    f.setVisible(true);               
            }
    }       
     
    class ButtonDemo extends JPanel implements ActionListener {
            JTextField jtf;
     
            public ButtonDemo() {
                    try {
                            makeGUI();
                    } catch (Exception exc) {
                            System.out.println("Can't create because of " + exc);
                    }
            }
     
            private void makeGUI() {
     
                    setLayout(new FlowLayout());
     
                    //THIS PART@@@@@@@@@@
                    ImageIcon ii=new ImageIcon("C:/Users/Jackson/Desktop/droplogger.png");                 
                    JLabel label=new JLabel(ii);  
     
                    ImageIcon DragonHatchet = new ImageIcon(
                                    "C:/Users/Jackson/Desktop/RS/Dragon_hatchet.gif");
                    JButton jb = new JButton(DragonHatchet);
                    jb.setActionCommand("Dragon Hatchet");
                    jb.addActionListener(this);
                    add(jb);
     
                    ImageIcon BerserkerRing = new ImageIcon(
                                    "C:/Users/Jackson/Desktop/RS/Berserker_ring.gif");
                    jb = new JButton(BerserkerRing);
                    jb.setActionCommand("Berserker Ring");
                    jb.addActionListener(this);
                    add(jb);
     
                    ImageIcon WarriorRing = new ImageIcon(
                                    "C:/Users/Jackson/Desktop/RS/Warrior_Ring.gif");
                    jb = new JButton(WarriorRing);
                    jb.setActionCommand("Warrior Ring");
                    jb.addActionListener(this);
                    add(jb);
     
                    ImageIcon ClueScroll = new ImageIcon(
                            "C:/Users/Jackson/Desktop/RS/Clue_scroll.gif");
                    jb = new JButton(ClueScroll);
                    jb.setActionCommand("Warrior Ring");
                    jb.addActionListener(this);
                    add(jb);
     
                    ImageIcon RuneSpear = new ImageIcon(               		
                            "C:/Users/Jackson/Desktop/RS/Rune_spear.gif");
                    jb = new JButton(RuneSpear);
                    jb.setActionCommand("Rune Spear");
                    jb.addActionListener(this);
                    add(jb);
     
                    jtf = new JTextField(15);
                    add(jtf);
     
            }
     
            public void actionPerformed(ActionEvent ae) {
                    jtf.setText(ae.getActionCommand());
     
                    }
            }

    When I run my program it only displays the 5 buttons and the text field. I've checked many times making sure the image name in the program matches with the one on my desktop. What am I doing wrong?


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,465
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: Everything but JLabel is displaying

    Indicate where in your code you add the label to the GUI.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Everything but JLabel is displaying

    ^^

    Same as Junky.

    You created the JLabel, but forgot to add it to your ButtonDemo/JPanel

Similar Threads

  1. JLabel placement issues
    By fride360 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 11th, 2011, 12:20 PM
  2. A problem with JLabel!
    By niklas in forum AWT / Java Swing
    Replies: 5
    Last Post: December 19th, 2010, 04:51 AM
  3. A problem with JLabel!
    By niklas in forum Member Introductions
    Replies: 1
    Last Post: December 14th, 2010, 05:03 PM
  4. JApplet containing JButton and a JLabel
    By JuneM in forum AWT / Java Swing
    Replies: 3
    Last Post: March 26th, 2010, 08:32 AM
  5. how to output using JLabel?
    By qaromi in forum AWT / Java Swing
    Replies: 1
    Last Post: August 30th, 2009, 02:09 PM