Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #18179 > unrolled thread

How to remove line around label image

Started byclusardi2k@aol.com
First post2012-08-20 10:18 -0700
Last post2012-08-20 14:16 -0400
Articles 10 — 3 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  How to remove line around label image clusardi2k@aol.com - 2012-08-20 10:18 -0700
    Re: How to remove line around label image Knute Johnson <nospam@knutejohnson.com> - 2012-08-20 11:09 -0700
      Re: How to remove line around label image clusardi2k@aol.com - 2012-08-20 12:11 -0700
        Re: How to remove line around label image Knute Johnson <nospam@knutejohnson.com> - 2012-08-20 13:14 -0700
          Re: How to remove line around label image clusardi2k@aol.com - 2012-08-21 05:28 -0700
            Re: How to remove line around label image Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-21 09:16 -0400
              Re: How to remove line around label image clusardi2k@aol.com - 2012-08-21 10:49 -0700
            Re: How to remove line around label image Knute Johnson <nospam@knutejohnson.com> - 2012-08-21 08:34 -0700
        Re: How to remove line around label image Knute Johnson <nospam@knutejohnson.com> - 2012-08-20 13:20 -0700
    Re: How to remove line around label image Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-20 14:16 -0400

#18179 — How to remove line around label image

Fromclusardi2k@aol.com
Date2012-08-20 10:18 -0700
SubjectHow to remove line around label image
Message-ID<824fad70-20cf-4b77-a9f1-296f6f1b8449@googlegroups.com>
How do I remove a line around a label image. I set the background and foreground color to the panel color and put a check in the property opaque checkbox.

Thank you,

[toc] | [next] | [standalone]


#18180

FromKnute Johnson <nospam@knutejohnson.com>
Date2012-08-20 11:09 -0700
Message-ID<k0tugm$4ed$1@dont-email.me>
In reply to#18179
On 8/20/2012 10:18 AM, clusardi2k@aol.com wrote:
> How do I remove a line around a label image. I set the background and
> foreground color to the panel color and put a check in the property
> opaque checkbox.
>
> Thank you,
>

We need to see some code.  I don't see the problem you describe in the 
code below.  Are you using AWT?

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.net.*;
import javax.swing.*;

public class test2 extends JPanel {
     private JLabel l;

     public test2() {
         super(new GridBagLayout());

         GridBagConstraints c = new GridBagConstraints();

         setPreferredSize(new Dimension(240,180));
         try {
             // use blue.png if you want to see the image
             URL url = new URL("http://knutejohnson.com/white.png");
             ImageIcon icon = new ImageIcon(url);
             l = new JLabel(icon);
         } catch (MalformedURLException murle) {
             murle.printStackTrace();
         }

         add(l,c);
     }

     public static void main(String[] args) {
         EventQueue.invokeLater(new Runnable() {
             public void run() {
                 JFrame f = new JFrame("test2");
                 f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                 test2 t2 = new test2();
                 f.add(t2,BorderLayout.CENTER);
                 f.pack();
                 f.setVisible(true);
             }
         });
     }
}



-- 

Knute Johnson

[toc] | [prev] | [next] | [standalone]


#18248

Fromclusardi2k@aol.com
Date2012-08-20 12:11 -0700
Message-ID<85bbe4c1-ffc8-405f-9fb5-53fb05e4941a@googlegroups.com>
In reply to#18180
> On Monday, August 20, 2012 2:09:26 PM UTC-4, Knute Johnson wrote:
> We need to see some code. I don't see the problem you describe in the code 
> below. Are you using AWT? 

Here is code that yields a tiny line around the image.

public class Line extends javax.swing.JFrame 
{
    public Line() 
    {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(51, 0, 153));
        setForeground(java.awt.Color.orange);

        jLabel1.setText("Remove Tiny Line");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(149, 149, 149)
                .addComponent(jLabel1)
                .addContainerGap(150, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(116, 116, 116)
                .addComponent(jLabel1)
                .addContainerGap(168, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>


    public static void main(String args[]) 
    {
        try 
        {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) 
            {
                if ("Nimbus".equals(info.getName())) 
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() 
        {

            public void run() 
            {
                new Line().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    // End of variables declaration

}

[toc] | [prev] | [next] | [standalone]


#18253

FromKnute Johnson <nospam@knutejohnson.com>
Date2012-08-20 13:14 -0700
Message-ID<k0u5rh$kmj$1@dont-email.me>
In reply to#18248
On 8/20/2012 12:11 PM, clusardi2k@aol.com wrote:
>> On Monday, August 20, 2012 2:09:26 PM UTC-4, Knute Johnson wrote:
>> We need to see some code. I don't see the problem you describe in the code
>> below. Are you using AWT?
>
> Here is code that yields a tiny line around the image.
>
> public class Line extends javax.swing.JFrame
> {
>      public Line()
>      {
>          initComponents();
>      }
>
>      @SuppressWarnings("unchecked")
>      // <editor-fold defaultstate="collapsed" desc="Generated Code">
>      private void initComponents() {
>
>          jLabel1 = new javax.swing.JLabel();
>
>          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
>          setBackground(new java.awt.Color(51, 0, 153));
>          setForeground(java.awt.Color.orange);
>
>          jLabel1.setText("Remove Tiny Line");
>
>          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
>          getContentPane().setLayout(layout);
>          layout.setHorizontalGroup(
>              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(layout.createSequentialGroup()
>                  .addGap(149, 149, 149)
>                  .addComponent(jLabel1)
>                  .addContainerGap(150, Short.MAX_VALUE))
>          );
>          layout.setVerticalGroup(
>              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(layout.createSequentialGroup()
>                  .addGap(116, 116, 116)
>                  .addComponent(jLabel1)
>                  .addContainerGap(168, Short.MAX_VALUE))
>          );
>
>          pack();
>      }// </editor-fold>
>
>
>      public static void main(String args[])
>      {
>          try
>          {
>              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
>              {
>                  if ("Nimbus".equals(info.getName()))
>                  {
>                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
>
>                      break;
>                  }
>              }
>          } catch (ClassNotFoundException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          } catch (InstantiationException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          } catch (IllegalAccessException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          }
>          //</editor-fold>
>
>          java.awt.EventQueue.invokeLater(new Runnable()
>          {
>
>              public void run()
>              {
>                  new Line().setVisible(true);
>              }
>          });
>      }
>      // Variables declaration - do not modify
>      private javax.swing.JLabel jLabel1;
>      // End of variables declaration
>
> }
>

I'm not seeing any line around the image or the JLabel.  A screen shot 
from my Windows XP with Java 7 computer here: 
http://http://knutejohnson.com/line.png.  What is your configuration?

Your code would be a boat load more readable with some imports.

-- 

Knute Johnson

[toc] | [prev] | [next] | [standalone]


#18267

Fromclusardi2k@aol.com
Date2012-08-21 05:28 -0700
Message-ID<97af3d30-77cb-4c81-baad-c4674fb5af66@googlegroups.com>
In reply to#18253
> On Monday, August 20, 2012 4:14:41 PM UTC-4, Knute Johnson wrote:
> I'm not seeing any line around the image or the JLabel. A screen shot from my 
> Windows XP with Java 7 computer here: 

Sorry, here is code that has a rock.gif icon attached to a label.

public class Line extends javax.swing.JFrame 
{
    public Line() 
    {
        initComponents();
    }


//FYI: I use a NetBeans form so the below code is grayed out. I.E.: I can't 
//modify it.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(51, 0, 153));
        setForeground(java.awt.Color.orange);

        jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Temp\\rock.gif")); // NOI18N
        jLabel1.setText("Remove Tiny Line");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(149, 149, 149)
                .addComponent(jLabel1)
                .addContainerGap(91, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(116, 116, 116)
                .addComponent(jLabel1)
                .addContainerGap(136, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>


    public static void main(String args[]) 
    {
        try 
        {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) 
            {
                if ("Nimbus".equals(info.getName())) 
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() 
        {

            public void run() 
            {
                new Line().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    // End of variables declaration

}

[toc] | [prev] | [next] | [standalone]


#18268

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2012-08-21 09:16 -0400
Message-ID<k101n5$tmu$1@dont-email.me>
In reply to#18267
On 8/21/2012 8:28 AM, clusardi2k@aol.com wrote:
>> On Monday, August 20, 2012 4:14:41 PM UTC-4, Knute Johnson wrote:
>> I'm not seeing any line around the image or the JLabel. A screen shot from my
>> Windows XP with Java 7 computer here:
>
> Sorry, here is code that has a rock.gif icon attached to a label.
> [...]

     Ran your code on my system: No tiny line.  I'll repeat an
earlier question: Are you sure this mysterious line isn't part
of the image you're displaying?

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#18270

Fromclusardi2k@aol.com
Date2012-08-21 10:49 -0700
Message-ID<a3d9c43b-1f80-42e6-9156-269f358b39b2@googlegroups.com>
In reply to#18268
> On Tuesday, August 21, 2012 9:16:20 AM UTC-4, Eric Sosman wrote:
> Are you sure this mysterious line isn't part of the image you're displaying? -- 

I think the line is indeed part of the image! It's an image just like the dancing baby image.

Thanks,

[toc] | [prev] | [next] | [standalone]


#18269

FromKnute Johnson <nospam@knutejohnson.com>
Date2012-08-21 08:34 -0700
Message-ID<k109qk$ftq$1@dont-email.me>
In reply to#18267
On 8/21/2012 5:28 AM, clusardi2k@aol.com wrote:
>> On Monday, August 20, 2012 4:14:41 PM UTC-4, Knute Johnson wrote:
>> I'm not seeing any line around the image or the JLabel. A screen shot from my
>> Windows XP with Java 7 computer here:
>
> Sorry, here is code that has a rock.gif icon attached to a label.
>
> public class Line extends javax.swing.JFrame
> {
>      public Line()
>      {
>          initComponents();
>      }
>
>
> //FYI: I use a NetBeans form so the below code is grayed out. I.E.: I can't
> //modify it.
>      @SuppressWarnings("unchecked")
>      // <editor-fold defaultstate="collapsed" desc="Generated Code">
>      private void initComponents() {
>
>          jLabel1 = new javax.swing.JLabel();
>
>          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
>          setBackground(new java.awt.Color(51, 0, 153));
>          setForeground(java.awt.Color.orange);
>
>          jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Temp\\rock.gif")); // NOI18N
>          jLabel1.setText("Remove Tiny Line");
>
>          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
>          getContentPane().setLayout(layout);
>          layout.setHorizontalGroup(
>              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(layout.createSequentialGroup()
>                  .addGap(149, 149, 149)
>                  .addComponent(jLabel1)
>                  .addContainerGap(91, Short.MAX_VALUE))
>          );
>          layout.setVerticalGroup(
>              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(layout.createSequentialGroup()
>                  .addGap(116, 116, 116)
>                  .addComponent(jLabel1)
>                  .addContainerGap(136, Short.MAX_VALUE))
>          );
>
>          pack();
>      }// </editor-fold>
>
>
>      public static void main(String args[])
>      {
>          try
>          {
>              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
>              {
>                  if ("Nimbus".equals(info.getName()))
>                  {
>                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
>
>                      break;
>                  }
>              }
>          } catch (ClassNotFoundException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          } catch (InstantiationException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          } catch (IllegalAccessException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          }
>          //</editor-fold>
>
>          java.awt.EventQueue.invokeLater(new Runnable()
>          {
>
>              public void run()
>              {
>                  new Line().setVisible(true);
>              }
>          });
>      }
>      // Variables declaration - do not modify
>      private javax.swing.JLabel jLabel1;
>      // End of variables declaration
>
> }
>

Again I'm not seeing any lines but I don't have the image.  Post the 
image some place.

What OS are you using?  What Java version?

Also, the code to set the look and feel must be run on the EDT.  Just 
put that code inside the EventQueue.invokeLater run method.

-- 

Knute Johnson

[toc] | [prev] | [next] | [standalone]


#18254

FromKnute Johnson <nospam@knutejohnson.com>
Date2012-08-20 13:20 -0700
Message-ID<k0u672$mi6$1@dont-email.me>
In reply to#18248
On 8/20/2012 12:11 PM, clusardi2k@aol.com wrote:
>> On Monday, August 20, 2012 2:09:26 PM UTC-4, Knute Johnson wrote:
>> We need to see some code. I don't see the problem you describe in the code
>> below. Are you using AWT?
>
> Here is code that yields a tiny line around the image.
>
> public class Line extends javax.swing.JFrame
> {
>      public Line()
>      {
>          initComponents();
>      }
>
>      @SuppressWarnings("unchecked")
>      // <editor-fold defaultstate="collapsed" desc="Generated Code">
>      private void initComponents() {
>
>          jLabel1 = new javax.swing.JLabel();
>
>          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
>          setBackground(new java.awt.Color(51, 0, 153));
>          setForeground(java.awt.Color.orange);
>
>          jLabel1.setText("Remove Tiny Line");
>
>          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
>          getContentPane().setLayout(layout);
>          layout.setHorizontalGroup(
>              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(layout.createSequentialGroup()
>                  .addGap(149, 149, 149)
>                  .addComponent(jLabel1)
>                  .addContainerGap(150, Short.MAX_VALUE))
>          );
>          layout.setVerticalGroup(
>              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(layout.createSequentialGroup()
>                  .addGap(116, 116, 116)
>                  .addComponent(jLabel1)
>                  .addContainerGap(168, Short.MAX_VALUE))
>          );
>
>          pack();
>      }// </editor-fold>
>
>
>      public static void main(String args[])
>      {
>          try
>          {
>              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
>              {
>                  if ("Nimbus".equals(info.getName()))
>                  {
>                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
>
>                      break;
>                  }
>              }
>          } catch (ClassNotFoundException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          } catch (InstantiationException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          } catch (IllegalAccessException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
>              java.util.logging.Logger.getLogger(Line.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
>          }
>          //</editor-fold>
>
>          java.awt.EventQueue.invokeLater(new Runnable()
>          {
>
>              public void run()
>              {
>                  new Line().setVisible(true);
>              }
>          });
>      }
>      // Variables declaration - do not modify
>      private javax.swing.JLabel jLabel1;
>      // End of variables declaration
>
> }
>

One other thing to consider is that look and feel must be changed from 
the EDT although I don't think that would cause this problem.

-- 

Knute Johnson

[toc] | [prev] | [next] | [standalone]


#18181

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2012-08-20 14:16 -0400
Message-ID<k0tuts$7oa$1@dont-email.me>
In reply to#18179
On 8/20/2012 1:18 PM, clusardi2k@aol.com wrote:
> How do I remove a line around a label image. I set the background and foreground color to the panel color and put a check in the property opaque checkbox.
>
> Thank you,
>

If you're sure the line is not part of the image itself (a border,
perhaps), please post an SSSCE.  This works fine for me:


     import javax.swing.ImageIcon;
     import javax.swing.JFrame;
     import javax.swing.JLabel;
     import javax.swing.SwingUtilities;
     public class Foo {
        public static void main(String[] unused) {
           SwingUtilities.invokeLater(new Runnable(){
              @Override
              public void run() {
                 JFrame frame = new JFrame("Foo");
                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 ImageIcon icon = new ImageIcon("icon.jpg");
                 frame.add(new JLabel(icon));
                 frame.pack();
                 frame.setVisible(true);
              }
           });
        }
     }

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web