Can I use a translucent picture as a main JFrame's icoimage?

¼

¼û·çʹ¶æ

Mainly code is like the flowing:
public class MyFrame extends JFrame {
public MyFrame (){
String logoPath ="c:/test.png"
ImageIcon icon =new ImageIcon(logoPath);
this.setIconImage(icon.getImage());
}
}

but the result is not right,the test.png looks distortion.

Can you help me?
 
J

John B. Matthews

º˚∑àπ∂Ê said:
Mainly code is like the f[ol]lowing:

You will perhaps get better answers if you post actual (rather than
similar) code:

<http://pscode.org/sscce.html>
import java.awt.EventQueue;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ImageIconTest {

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
//@Override
public void run() {
ImageIcon img = new ImageIcon("image.png");
JFrame f = new JFrame("Frame");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setIconImage(img.getImage());
f.add(new JLabel(img));
f.pack();
f.setVisible(true);
}
});
}
}
but the result is not right,the test.png looks distortion.

Perhaps you can supply a link to the image or describe more fully what
you mean by "distortion". Not all platforms support the concept of
minimizing a window.
 
È

è§é£Žä½¿èˆµ

 º˚∑àπ∂Ê said:
Mainly code is like the f[ol]lowing:

You will perhaps get better answers if you post actual (rather than
similar) code:

<http://pscode.org/sscce.html>
import java.awt.EventQueue;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ImageIconTest {

  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      //@Override
      public void run() {
        ImageIcon img = new ImageIcon("image.png");
        JFrame f = new JFrame("Frame");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setIconImage(img.getImage());
        f.add(new JLabel(img));
        f.pack();
        f.setVisible(true);
      }
    });
  }}

but the result is not right,the test.png looks distortion.

Perhaps you can supply a link to the image or describe more fully what
you mean by "distortion". Not all platforms support the concept of
minimizing a window.

Thank you for your answers.But the problem still exist.
I don't want "minimizing a window".
I mean that the icon of the JFrame looks rough,not clear differ to the
origin image.png file.
The color of the origin image.png file is 16-bit True Color,But the
runtime result is not .

Why?Can you help me? Thank you very much.
 
J

John B. Matthews

ºš…Á ¼Ê said:
ݺš…Á ¼Ê said:
Mainly code is like the f[ol]lowing:

You will perhaps get better answers if you post actual (rather than
similar) code:

<http://pscode.org/sscce.html> [...]
but the result is not right,the test.png looks distortion.

Perhaps you can supply a link to the image or describe more fully
what you mean by "distortion". Not all platforms support the
concept of minimizing a window.

[Please trim sigs when responding.]
Thank you for your answers. But the problem still exist. I don't want
"minimizing a window".

I don't know how else to interpret the API for JFrame#setIconImage():
"Sets the image to be displayed in the minimized icon for this frame.
Not all platforms support the concept of minimizing a window." On my
platform, a minimized window shows a thumbnail of the frame's content
pane overlain by a cup of coffee; invoking setIconImage() has no
apparent effect.
I mean that the icon of the JFrame looks rough, not clear differ to
the origin image.png file. The color of the origin image.png file is
16-bit True Color, but the runtime result is not. Why?

You might try a different image format, a different image, or an image
that has been scaled to display clearly at the required size.
Can you help me?

As setIconImage() does nothing on my platform, no. You will perhaps get
a more helpful answer if you post a link to the image, the code, and a
 
A

Arved Sandstrom

As setIconImage() does nothing on my platform, no. You will perhaps get
a more helpful answer if you post a link to the image, the code, and a
screenshot showing the problem. I use <http://sites.google.com>, but
alternatives abound.

Agreed. I'm half interested in the OP's problem, and would be willing to
test on various flavours of Windows, Linux and Mac OS X, but since we
don't have enough information about the image (in fact, we need the
specific image), and I'm unclear as where the app icon is problematic,
it's tough to help out.

AHS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top