How to set icon that fit(stretch) to JLabel?

Let say i have aa image(w = 50, h = 50) and JLabel(w = 100, h = 100)
how to fit the image to JLabel by JLabel.setIcon(image)?
thx..

Ooop... sorry u mean getScaledInstance right, by the way which the faster way to scale image? code 1 or code 2
Code 1.
public ImageIcon create_Thumbnail(ImageIcon img,int w , int h ){
        img = new ImageIcon(img.getImage().getScaledInstance(w, h, BufferedImage.SCALE_SMOOTH));
        return  img;
}Code 2
    public ImageIcon create_Thumbnail(ImageIcon img,int w , int h ){
        BufferedImage bi;
        bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = bi.createGraphics();     
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2.drawImage(img.getImage(), 0, 0, w, h, null);
        g2.dispose();
        return new ImageIcon(bi);
    }

Similar Messages

  • How to set Icon on MenuItem

    How to set icon on MenuItem, but not in JMenuItem?

    saleemtol003 wrote:
    You are right.It's not possible to set icon on menuItem.
    I am talking about SystemTray in which I added PopupMenu with MenuItem.
    but I need MenuItem with icon.Is there another way to solve this problem?Nope, just because you're adding a PopupMenu to a TrayIcon does not change the fact that MenuItems cannot have icons.

  • How to set icon image in jstudio for my application

    Dear friends,
    I developed one application in jstudio.And need to set an special icon for my application.While i download my application in to mobile. The icon should be displayed in the mobile.To show my application as unique from other applications.But i dont know how to set an icon for my application. If any one find answer please reply as soon as possible.
    Thank you

    Java Studio Enterprise per se does not support creating applications for mobile devices. I gues you used NetBeans Mobility Pack for that. Therefore, please refer to http://mobility.netbeans.org/ for more information. Thanks.
    Here is a FAQ entry, which, as far as I understand answers your question: http://www.netbeans.org/kb/faqs/j2me-mobility.html#FaqJ2MESpecifyMidletIcon

  • How to set icon for .lnk on PPC

    I'm using the Mysaifu JVM and I would like to know how to set an icon of my choice for the shortcut file to my application (.lnk). Currently, the Mysaifu character shows up as the icon.
    On a previous post, I found out how to run my java application using the following text in my .lnk file:
    255#"\Program Files\Mysaifu JVM\jre\bin\jvm.exe" -Xhidevmwindow -Xmx5M -jar "\My Documents\DeliveryOrganizer.jar" DeliveryOrganizer
    Please help!!!
    Your help would be much appreciated!
    Thanks!

    I don't think you're going to have much luck modifying the original link, since the jvm.exe is what the link is pointing to. Windows Mobile is getting its icon from the jvm.exe, and not the DeliveryOrganizer jar file.
    However, you might look into creating a separate .lnk file, that then calls your original .lnk file that executes the jvm.exe. See if Windows Mobile allows you to modify the new .lnk file's properties...

  • How to Set icon/image programatically in ADF before page loads

    This is my UI:
    Depends on the condition i want to set icon/image programatically in my java code.Before page load im calling this method.
    So i couldnt take binding value also,it throws null pointer exception.Then i tried setting icon/image programatically.
    <af:commandImageLink text="settings" icon="#{bean.iconsettings}" binding="#{bean.bind}"> </af:commandImageLink>
    My bean:
    private RichIcon iconsettings;(its getters and setters)
    private void method(){                         // method
    if(cond){
    this.iconsettings="/images/20.jpg";   //trying to set icon in a string.but it throws me error that cannot set RichIcon to string.
    else
    this.iconsettings="/images/19.jpg";
    Could any one tell me how can i set icon/image in java code.Before page loads im performing all above said tasks.Please help.

    Well, you set the icon property to a bean method, which you have done. The bean method however need to have the signature
    public String getIconsetting()
    // your code returning hte path to the icon
    if(cond){
         return ="/images/20.jpg";   //trying to set icon in a string.but it throws me error that cannot set RichIcon to string.
    else {
         return ="/images/19.jpg";
    The bindproperty is not needed, remove it and remove the RichIcon Iconsettings too´as it's not needed to and is the wrong type anyway.
    Timo

  • How to set variables that queries can use?(10g)

    I am using only ONE TABLE here for all queries. I have one query which pulls out a key and seven other queries that create seven different report sections based on that key. All queries access data in the same table.
    The first query ahould set a key so the other seven can use that key to get data. The key changes everytime all seven queries get executed and a report page is displayed, then the queries use the new key until all keys generated by the first query are used.
    Questions?
    How do I get the seven queries to check that key. Can you have (declare) variables in Reports Builder that you can assign a value in every iteration and then include a check (for that value)in a where clause of other queries? If yes how would I do that?
    In a programming language this is simple, you pass the same value as a parameter to several functions... Can you do something similar here and set a value that all queries can check against? Like a local or global variable.
    Thanks
    Mike

    Sorry, I guess there were a few typos in my last post!
    OK. All data is pulled from the same table. Here is how the report should look:
    KEY (a number)
    Data from query 1 that belongs to key above
    more Data from query 1 that belongs to key above
    more Data from query 1 that belongs to key above
    Data from query 2 that belongs to key above
    more Data from query 2 that belongs to key above
    more Data from query 2 that belongs to key above
    Data from query 3 that belongs to key above
    Data from query 4 that belongs to key above
    Data from query 5 that belongs to key above
    Data from query 6, same
    Data from query 7, same
    END OF PAGE 1
    (there is a maximum 45 possible data lines so data will not exceed the length of a page)
    Next Page:
    KEY (a different number)
    Data from query 1 that belongs to key above
    more Data from query 1 same
    more Data from query 1 same
    Data from query 2 same
    more Data from query 2...
    more Data from query 2....
    Data from query 3 same
    Data from query 4...
    Data from query 5.....
    Data from query 6....
    Data from query 7....
    END OF PAGE 2
    Other pages all look the same. Data from each query is based on the key on the first line and so on.
    Example:
    select ipseries from ipTable (possibly for query 1)
    select ipSeries,sum(ipvalue1+ipValue2+ipvalue3) from ipTable (query1) group by....
    select (sum(ipvalue1+ipValue2+ipvalue3)/3) from ipTable (query2)
    select (sum(ipvalue1*ipValue2*ipvalue3)) from ipTable (query3)
    and so on. Each query puills a set of values or sums a set of values.... etc.
    (please note that what I have not included is that somehow we need to relate each query with the key)
    Thanks a lot

  • How to set icon in JavaHelp frame?

    Hello everybody
    I'm using JavaHelp 2.0 for the first time and I have been told that it is possible to set the icon within the JavaHelp frame. Furthermore it should be possible to set the position of the help window.
    I used the following code within my Java class to start JavaHelp, as the help frame should appear, when the user clicks on "JavaHelp" within the "Help" menu:
        JMenu helpMenu = new JMenu("Help");
        try {
          URL hsURL = new File("javahelp/DbManager.hs").toURL();
          HelpSet hs = new HelpSet(null, hsURL);
          HelpBroker hb = hs.createHelpBroker();
          menuItem = new JMenuItem("JavaHelp");
          menuItem.addActionListener(new CSH.DisplayHelpFromSource(hb));
          helpMenu.add(menuItem);
        } catch (Exception e) {
        }My helpset is called "DbManager.hs" and here's the presentation section of it (of course the image "dbmanager.title.image" is defined within the map file):
      <!-- presentation -->
      <presentation default="true" displayviews="true" displayviewimages="false">
        <name>MainWindow</name>
        <size width="600" height="500" />
        <location x="200" y="200" />
        <title>Database Manager</title>
        <image>dbmanager.title.image</image>
      </presentation>When I start the JavaHelp it does not show the Icon and it does not set the size and location accordingly.
    I'd be very glad for any hint on what I might be overlooking.
    Thanks,
    Christian

    Hi,
    You need to specify the name of your presentation in the createHelpBroker call:
        JMenu helpMenu = new JMenu("Help");
        try {
          URL hsURL = new File("javahelp/DbManager.hs").toURL();
          HelpSet hs = new HelpSet(null, hsURL);
          HelpBroker hb = hs.createHelpBroker("MainWindow");
          menuItem = new JMenuItem("JavaHelp");Then it should work.
    Brendan

  • How to set icon in JDialog

    In JFrame there is method setIconImage(Image) for setting image icon on title bar , but in case of JDialog how to it?

    In case you have not mentioned the owner of JDialog, java sets a hidden frame as its owner.Thefore you can set the icon on a JDialog dialog by
    ((java.awt.Frame)dialog.getOwner()).setIconImage(Image);
    Regards
    Shashi

  • How to set icon for JTree

    hi,
    I have a JTree. For this JTree i have a DefaultJTreeCellRenderer.
    i have done like this
    JTree tree = new JTree();
    DefaultJTreeCellRenderer renderer = new DefaultJTreeCellRenderer();
    renderer.setOpenIcon(....);
    renderer.serCloseIcon(...);
    tree.setCellRenderer(renderer);but this is not working.
    how to change the icons of the node when i click
    thank you

    public class Test extends JFrame implements ActionListener {
         private static final long serialVersionUID = 1L;
         private JButton buttonCreate;
         private JTree tree;
         private DefaultMutableTreeNode defaultMutableTreeNode;
         private DefaultTreeModel defaultTreeModel;
         private int i;
         public Test() {
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              layoutComponents();
              setSize(400, 400);
              setLocationRelativeTo(null);
              setVisible(true);
         private void layoutComponents() {
              defaultMutableTreeNode = new DefaultMutableTreeNode("Root");
              defaultTreeModel = new DefaultTreeModel(defaultMutableTreeNode);
              tree = new JTree(defaultTreeModel);
              tree.setRootVisible(false);
              buttonCreate = new JButton("Create");
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(tree, BorderLayout.CENTER);
              getContentPane().add(buttonCreate, BorderLayout.SOUTH);
              DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
              ImageIcon icon_close = new ImageIcon("./images/project_closed.gif");
              ImageIcon icon_open = new ImageIcon("./images/project_opened.gif");
              renderer.setOpenIcon(icon_open);
              renderer.setClosedIcon(icon_close);
              tree.setCellRenderer(renderer);
              buttonCreate.addActionListener(this);
         public static void main(String[] args) {
              new Test();
         public void actionPerformed(ActionEvent e) {
              addElementToParent("Child" + i++);
         private DefaultMutableTreeNode addElementToParent(Object theChild) {
              return addElementToParent(defaultMutableTreeNode, theChild, true);
         private DefaultMutableTreeNode addElementToParent(DefaultMutableTreeNode theParent, Object theChild, boolean shouldBeVisible) {
              DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(theChild);
              if (theParent == null) {
                   theParent = defaultMutableTreeNode;
              defaultTreeModel.insertNodeInto(childNode, theParent, theParent.getChildCount());
              TreePath childTreePath = new TreePath(childNode.getPath());
              //          Make sure the user can see the lovely new node.
              if (shouldBeVisible) {
                   tree.scrollPathToVisible(childTreePath);
              tree.requestFocusInWindow();
              return childNode;
    }this is the code which i was trying to execute.
    here i want to explain you is
    when i click the node the icon should change to open_icon
    when i click the other node the previous node icon should change to close_icon
    how is this possible
    null

  • How to set icon to a file type??

    How to assign an icon to the application generated file?
    Thanks in advance.

    What GUI do you work with?
    I assume you want to see the icons in Windows. You will have to modify the registry, possibly by some native API call. Have a look at the MSDN library then.
    Hiran

  • How to set up that a CRM order is transferred to SCM?

    Where must the setting be done that a CRM order is transferred to SCM?

    Hi,
    You have to do the middleware config in CRM and few settings in SCM system to replicate orders. After doing the setting you have to start the initial load and then the delta load will be taken care automatically based on settings.
    Go through the below link it might help.
    http://help.sap.com/saphelp_sm40/helpdata/EN/3f/40623c046a9b67e10000000a11402f/frameset.htm
    Regards,
    Sanjay

  • How to set argument that is file contents?

    I'm developing a JWS app.
    My main class needs one file from server(contents of it, not just filename, file is a XML) in which writes some data and sends it back to server.
    I nead help. What is the easiest way to do this?
    Does JNLP <argument>arg1</argument> tag does this?
    Please help.
    Thanks.

    The argument tag sets an argument.
    Basically, you have to do the rest.
    Setting the argument allows you to change the name,
    for example.OK.
    Can you help me with some example on how to get a file from server and send a file to server?
    Which class is used for it (URI, URL or something else)? I would appreciate an example.
    Thank you.

  • How to set reminder that I am closing multiple tabs?

    On another computer, I had set a reminder to warn me if I was
    closing more then one tab. I cannot find a way to set this warning on a different computer.
    Handicapped and need simple answer.

    Tools > Options > Tabs: [√] "Warn me when closing multiple tabs"

  • The icon that allows connection to multiple speakers is gone, how do i get it back?

    I am not sure how, but the icon that allows for mulitple speakers has disappeared from my Itunes.  How do I get it back? I had a problem with Bonjuor and I believe this is the cause of the issue, but I reloaded it and I still don't have the icon.  Apple TV can connect to my library, but I have no control over multiple speakers from my PC.  I alos have an Airport Express running off this same system.

    youre voice to text option is not gone.Please go into settings and get into accessibility and turn on voice selection.If voice selection is on please restart the iphone.Also turn on siri.
    Hope your problem will be solved
    Thanks

  • How to make my website fit to all resolution?

    Hi all, I'm a beginner for using dreamweaver.  I've been looking for this question but I think it doesn't solve my problem. I want to make my website fit to all screen resolution. At first, I preview it at mozilla  and Internet explorer and its ok. But my friend say that she open it at her computer , Ipad it become a mess. I try to open it at public computer too and it's really such a mess.
    I used dreamweaver cs6
    And now my problem is:
    How to set it to fit for all screen resolution?
    what is the css code to make it fit to all screen resolution?
    How to set normal  width and height for website?
    this is how my css work:
    @charset "utf-8";
    .mainbody {
        background-color: #CCC;
        width: 980px;
        margin-right: auto;
        margin-left: auto;
    .mainbody .header {
        height: auto;
        width: 980px;
        padding-top: 15px;
        padding-bottom: 10px;
    .mainbody .menubar {
        width: 980px;
        height:auto;
        padding-top: 10px;
        padding-right: 0px;
        padding-bottom: 10px;
        padding-left: 0px;
    .mainbody .slider {
        width: 972px;
        height: auto;
        padding-top: 15px;
        padding-bottom: 15px;
        border: medium dotted #60F;
        margin-top: 25px;
        margin-bottom: 15px;
    Please let me know is there's any mistake i've made. 
    By the way , sorry for my bad English ^_^

    Thank you for your reply ^_^
    this is my website : www.favoritepumps.com
    It's very very very simple right >.<
    but in this website I use the dreamweaver template . few days ago I make my own use div tags and i'ts been mess and I changed it back.
    and now I just want to know how to set it fit to all screen resolution and how about the width I make?
    I got some information that the width shouldn't be more than 980 px is it true?
    how should I write then?
    I make it like this at the source code:
    <div class="mainbody">
        <div class="header"><img src="images/favoritepump.png" width="500" height="80" alt="favoritepumps" /></div><!-- end .header -->
        <div class="menubar">
          <ul id="MenuBar1" class="MenuBarHorizontal">
            <li>
              <div align="center"><a class="MenuBarItemSubmenu" href="#">Item 1</a>
                <ul>
                  <li><a href="#">Item 1.1</a></li>
                  <li><a href="#">Item 1.2</a></li>
                  <li><a href="#">Item 1.3</a></li>
                </ul>
              </div>
            </li>
            <li>
              <div align="center"><a href="#">Item 2</a></div>
            </li>
            <li>
              <div align="center"><a class="MenuBarItemSubmenu" href="#">Item 3</a>
                <ul>
                  <li><a class="MenuBarItemSubmenu" href="#">Item 3.1</a>
                    <ul>
                      <li><a href="#">Item 3.1.1</a></li>
                      <li><a href="#">Item 3.1.2</a></li>
                    </ul>
                  </li>
                  <li><a href="#">Item 3.2</a></li>
                  <li><a href="#">Item 3.3</a></li>
                </ul>
              </div>
            </li>
            <li>
              <div align="center"><a href="#">Item 4</a></div>
            </li>
            <li>
              <div align="center"><a href="#">Untitled Item</a></div>
            </li>
          </ul>
        </div><!-- end .sidebar -->
        <div class="slider">
          <div align="center"><img src="images/kero.jpg" width="250" height="220" alt="kero" /></div>
        </div><!-- end .slider -->
        <div class="container">
            <div class="leftbar"> </div><!-- end .leftbar-->
             <div class="rightbar"></div><!--end .rightbar -->
        </div><!-- end .container2 -->
        <div class="footer"></div><!-- end .footer -->
    </div><!-- end .mainbody -->
    thank you

Maybe you are looking for