Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2007

Tip: Looking for answers? Try searching our database.

Image on a button

Thread view: 
Chanchal - 25 Oct 2007 01:40 GMT
Hello All,
I have a JSplitPane on a JFrame. Left side of the JSplitPane contains
a button with an image on it.
i want the image to get resized along with the button when the divider
of the JSplitPane is dragged. Kindly advice how this can be achieved.

This is my code

import javax.swing.*;

public class NewJFrame extends JFrame {

   JButton jButton1;
   JButton jButton2;
   JSplitPane jSplitPane1;

   public NewJFrame() {
       jSplitPane1 = new JSplitPane();
       jButton1 = new JButton();
       jButton2 = new JButton();

       setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
       jButton1.setIcon(new ImageIcon(getClass().getResource("/
background1.png")));
       jSplitPane1.setLeftComponent(jButton1);

       jSplitPane1.setRightComponent(jButton2);

       getContentPane().add(jSplitPane1,
java.awt.BorderLayout.CENTER);

       pack();
   }

   public static void main(String args[]) {
        new NewJFrame().setVisible(true);
   }

}

Thanks in advance

Chanchal
Andrew Thompson - 25 Oct 2007 02:07 GMT
...
>I have a JSplitPane on a JFrame. Left side of the JSplitPane contains
>a button with an image on it.
>i want the image to get resized ..

<zen question>
Using which image scaling algorithm?
</zen question>

> ...along with the button when the divider
>of the JSplitPane is dragged. Kindly advice how this can be achieved.

I suspect you would need to overide JButton to paint
the image according to the width/height.  This can be
done using a very simple, generic rescaling algorithm,
using one of the Graphics.drawImage() methods that
accepts a width/height.

Signature

Andrew Thompson
http://www.athompson.info/andrew/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.