JLabel - setSize

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thesti
    New Member
    • Nov 2007
    • 144

    JLabel - setSize

    hi,

    i have a JLabel inside a JPanel of which layout manager is BoxLayout. i will display an image with the JLabel at runtime,

    when the application first start, it will appear as an empty box with border. i've set the border for the JLabel, but then it appears as a small rectangle, i've tried to use the setSize and the setMinimumSize but still it appears so small. how to make it be displayed with a fixed size even if it's empty (contains no text).


    thank you very much.
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    Does it have to be a JLabel? Try an ImageIcon, my experiece with images and JLabels is not that pleasant.

    /MK

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by MarkoKlacar
      Hi,

      Does it have to be a JLabel? Try an ImageIcon, my experiece with images and JLabels is not that pleasant.

      /MK
      An AWT container can only contain Components; an ImageIcon isn't a Component.
      You do have to use a Component that is able to contain some form of a picture.
      A JLabel is a good option.

      kind regards,

      Jos

      Comment

      • chelvan
        New Member
        • Aug 2008
        • 90

        #4
        hi
        try like this

        Code:
        JLabel lbl1=new JLabel(new image("image.jpg"));
        regards
        chel-1

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by chelvan
          hi
          try like this

          Code:
          JLabel lbl1=new JLabel(new image("image.jpg"));
          regards
          chel-1
          Read Jos' post above about ImageIcon again.

          Comment

          • chelvan
            New Member
            • Aug 2008
            • 90

            #6
            Originally posted by r035198x
            Read Jos' post above about ImageIcon again.
            so
            can i change the code like this
            Code:
            JLabel lbl1=new JLabel(new ImageIcon("image.jpg"));
            chel-1

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by chelvan
              so
              can i change the code like this
              Code:
              JLabel lbl1=new JLabel(new ImageIcon("image.jpg"));
              chel-1
              What happens when you try that? I hope you have the specs for JLabel and ImageIcon open with you for reference as you try these things.

              Comment

              Working...