How to make an imageicon to be resized to fit the button

Hi all,
I am working on this problem, which has a JButton, Image and Text all one above another . The graphic here is a rectangular box.
The application works fine for an 800 X 600 resolution, but when the resolution is changed to 1024 X 728, only the Jbutton and the text are getting bigger(logic already present), but not the graphical icon which sits on top of the button.
So I tried to scale the image and then redraw it using the drawImage() of the graphics object. But it wouldnt show up, so i set the Opaque property to false for the Jbutton, to make the image visible. Then the image showed up as wanted, but when a mouse click event occurs on that button,the button is not getting highlighted and some weird behaivour happens.
If anyone can throw some light on this, i would greatly appreciate it.
Thanks in advance

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ImageOnButton extends JFrame { 
public ImageOnButton() {   
  ImageIcon icon = new ImageIcon("SndImage.jpg");
    JPanel content = (JPanel)getContentPane();
    content.setLayout(new FlowLayout());
    JButton myButton = new MyButton("I am Button",icon.getImage());
    content.add(myButton);
    this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
public static void main(String[] args) {
    ImageOnButton test = new ImageOnButton();
    test.setSize(200,200);
    test.show();
  class MyButton extends JButton {
    Image image;
    public MyButton(String Text, Image Image) {
      super(Text);
      setOpaque(false);
      image=Image;
    public void paint(Graphics g) {
      g.drawImage(image, 0,0, getWidth(), getHeight(), this);
      super.paint(g);
}

Similar Messages

  • In windows 7, how to make firefox start automatically when I turn on the computer

    In Windows 7, how to make Firefox start automatically when I turn on the computer. Note, I am asking how to do this with Windows 7, not xp, not vista.

    You need to place a shortcut to open Firefox in the Start > Programs > Startup folder.<br />
    That is basically the same in all Windows versions.

  • How to make a select list editable or searchable like the combobox

    Does anybody know, How to make a select list editable or searchable like the combobox? Do we need a plugin here, where I can get it.

    Hi Nilesh,
    If this is what you are looking for http://apex.oracle.com/pls/apex/f?p=32395:3:1202144397644679
    get the combobox plug-in
    http://www.apex-plugin.com/oracle-apex-plugins/item-plugin/searchable-combobox.html
    I have not tried this though. Found it while searching for some other plug-ins.
    Regards,
    -Senthil

  • How to make a summary column appear only once (in the first page only) in SSRS 2008?

    Hello Everyone,
    How to make a summary column appear only once (in the first page only) in SSRS 2008?
    Regards
    Gautam S
    Regards

    Hi,
    Assuming you have test data like this ;
    select 'abc'as [GROUP],'NN' name , 1 id
    union all
    select 'abc' as [GROUP] ,'PP' name , 1 id
    union all
    select 'abc'as [GROUP],'RR' name , 2 id
    Step1  : take Tablix with row group as your group Name .
    Step2 : right Click on Row Group Details -> Delete-> Delete Group Only
    Step3 : In Count Cell use below expression ;
    =CountDistinct(Fields!id.Value)
    Follow this link;
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b6b45917-0a26-4d15-be46-2c6a2697d6e9/distinct-rows-sum?forum=sqlreportingservices#5ffdee06-c2c8-44ea-a3a5-b958488bb6b5
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

  • Picture can not be resized to fit the screen, so i can only see half of my face when use it as wallpaper!! Suckss!!

    picture can not be resized to fit the screen, so i can only see half of my face when use it as wallpaper!!  How can I change it??

    There's a bug with the wallpaper. One thing that helps a bit, go to the photos app, find your pic, 'send' it to be wallpaper. You have a bit more control although not all the function you're used to.
    No idea when or if Apple will fix it.

  • TS3274 How do I re-boot my IPad?   Where are the buttons to push?

    How do I re-boot my IPad?  Where are the buttons I push?

    Pess and hold the home and sleep/power  buttons at the same until the Apple logo shows.

  • How to make it sound as if it is in the next room.

    I am new to the audio editing/mixing.
    I am curious how to make dialog sound as if it is happening in the next room.
    I vaguely remember a setting that was doing something like it and it was actually called similarly (In the next room), but now I can't find it.
    If it doesn't exist and it was one of those borscht induced nightmares, how one would approach this anyway?
    Thanks a lot in advance.

    In the effects rack, there are several "room" settings you can apply, and tweak the parameters to make it sound as if it's in the same room or next door.

  • How to make my music library on my iPhone appear the way I wanted?

    Hi there, I have created my own music library by ligit CDs and have purchased some songs through iTunes, it is saved onto my macbook pro, since I have songs in Chinese, Japanese and English, I have re-arranged and re-editded my music library my own way of song titles, artist names, album titles, artwork, year of album release etc (part of the reason is that sometimes song data from iTunes were incorrect). And, I would like to duplicate my music library / playlist in the same way of appearance on my iPhone 5s and iPod touch, I have turned off all the auto downloads on music settings and iCloud settings, and I am only copying my music from Macbook to iPhone through a cable, but it still won't work and still appear how the song, artist, artwork was shown in iTunes.
    Is there any way to make it work? Its really frustrated as the data of the songs are incorrect, I could change anything in my library in my Macbook, but I can't duplicate that onto my iPhone and iPod.....
    Thanks a lot...!

    This article may help
    https://discussions.apple.com/docs/DOC-3991

  • How to make round curves when you are animatting with the Rec mode?

    Hi! I am making a project in motion. I recored a freind writing words and stuff in the roof of my house with two flashlights. My plans was to follow the lights with motion traking: Analize move or match move. And then add a particle emmite for making something like this: http://www.youtube.com/watch?v=MZf2W3S7gV0&feature=fvw . When i tried to make the match move it was imposible. So i desided to make it manually with the REC button. And it work perfectly, the only problem is that it can's achive the round cruves (bezier like). I can only make squared like turns and it looks awful. I have also tried bezier as a path but i don't know how to make the particle emmiter follow it with different speeds, becouse the movement of the flashlight is inconstant.
    What can i do to make a round curved path and make a particle emmiter follow it with the rec button with the different speeds of the flashlights? Please help me!!!! I have to deliver this work for tuesday!
    Thanks for you time y hope you can help me out as soon as possible.
    Juan Javier.
    PD Sorry for my english! jajajaja.

    Juan Javier Ibarra Pitts wrote:
    When i tried to make the match move it was imposible.
    Hi
    Why was it impossible?
    It sounds like tracking is the only way your going to achieve what your after given the way you've shot your footage and the spatial and temporal nuances therein.
    You'll find comprehensive instructions on how to track particles to footage starting on page 49 of this document:
    http://manuals.info.apple.com/en/MotionSupplementalDocumentation.pdf
    Regards.

  • How to make a video stop in flash through an external button

    Hi everyone!
    I have a little problem: I made a flash site with its
    different sections, the first of which has a movie clip which is a
    "VideoPlaylist". So inside this movie clip I have the player and
    the videos sequenced one after the other in a TileList component.
    The problem is:
    When I go to a different page, the video in the first page
    continues to play and so you can still hear the sound, AND WHICH IS
    WORSE, when you click the button to return to the first page, the
    video starts again with the sound of the previous time still
    rolling.
    The solution would be, I suppose, when clicking to any of the
    buttons that link to another section of the flash document, add
    some action script to make the video stop (having in mind that the
    video player is inside a movie clip).
    I don't know action script, just the navigation basics
    necessary for the sections. I did the videoplaylist following this
    tutorial:
    http://www.adobe.com/devnet/flash/articles/video_playlist.html
    Can anyone help me, please!!

    You better ask in the Flash forum; this is the Flash Player forum.

  • How to make a common parameter for two subreports in the main report.

    Hi,
    I have a crystal report which has 2 subreports in it. Both the subreports have the same code and I need to create a parameter for Project Cost in both the subreports for filtering the data.
    When i create the same parameter in both the subreports, i see two parameters with same name on my prompt page while refreshing the report. however I just want 1 parameter on my prompt page and data should get filtered in both the reports.
    Can anyone please suggest something, How can I do that? is there a way for sharing same parameter between two subreports?
    Thanks!
    Neha.

    hi Neha,
    here's how to do this:
    1) create a new parameter with the same name on the main report
    2) right click on your first subreport and choose Change Subreport Links
    3) in the Field to Link To list drag over your new main report parameter
    4) open the Subreport Parameter Field to Use select menu and choose your subreport parameter
    5) repeat steps for the 2nd subreport
    now you'll only get prompted once.
    cheers,
    jamie

  • How to make JTable editable by me but not by the user?

    Hi. I am doing an application to show data in a JTable.
    I need to update the data but do not want the user to change the data.
    Could somebody tell me how to do it?
    Thanks a lot!

    Yes, the above solution is clean. To add a little bit, if you donot want to have a JDialog to your application, just check for the password that is sent in an argument at the start of the application.
    java MyApp <password> // to be run by you
    java MyApp // to be run by user
    This would check the password and then sets the edit mode for the table. (But mind you, this can be done only at the start). If you want to determine the editing mode during the runtime, then you have to go for a login dialog. But, as far as I can imagine, you develop the application and will give it to the user. Is that correct?
    Thanks,
    Kalyan

  • How do I capture selected record ID when I pressed the Button

    Hi
    I have a repdort with below query.
    select
    empno, ename, job, sal,
    '<input type="button" value="Employee" />' "Select"
    from emp
    This query gives each row a button. When I press a button of a particular row I wanted to capture that row empno field value. How can I do this?
    Regards
    kiran Akkiraju

    If you are trying to make the button do a submit to this page or another page to see employee detail, you are probably better off creating a link on you column in the "Report Attributes" section that will make the column a hyperlink (text or image, you can pick) (see How can i make a linking column in a report it has a link to a how-to from Oracle and some HTML formatting hints to make the link more informative with ALT text)
    Here is one way to capture the selected employee number. Hopwever, it will not submit the form though. You can put the value of empno into another field using javascript. The Pxxx_destination_field is the name of the field on the page you want to push the empno into.
    select
    empno, ename, job, sal,
    '<input type="button" onclick="javascript:html_GetElement(''Pxxx_destination_field'').value = ' || empno || ';" value="Employee" />' "Select"
    from emp

  • How can I stop iTunes from launching when I hit the button on my head phones

    On my MBP I have some head phones that have an inline mic with call answer button. The button on the head phones is fairly sensitive and I tend to bump it on accident often. When I hit the button iTunes is launched or if I have it open it starts music.
    Is there anyway to stop this from happening? This is driving me crazy!

    This problem has been an issue for a number of months and has led to frustration and public humiliation on countless occasions.
    When disconnecting from my Bose Soundlink at home (playing nothing) in order to taking my laptop on the run I open my laptop to find that the entire contents of my iTunes playlist is being belted in public. The subway, the library, my classroom is not the time or place for my laptop to make the decision to begin playing my music without permission. When at home and my Soundlink goes on standby I have nearly had a heart attack when my laptop spontaneously begins blaring my music when I wasn't even touching the thing.
    I love my Soundlink and I love my Mac but together the devices are causing no end of aggravation with no fix in sight. With each OS update I hope the problem is addressed but to no avail, it is getting tiresome that such a flaw isn't being fixed in a timely manner.

  • How to make the text resize to fit the window ?

    Hi,
    I'm making a website using Adobe Edge and I want the text to resize when the window is resized too. I tried some jQuery plugins but had no success. Any help would be greatly appreciated.
    Thanks in advance,
    Rafael Carignato

    See this post your question was already answered there:
    http://forums.adobe.com/message/5045627#5045627
    Here is a sample file of text that re-sizes according to window size:
    http://www.meschrene.puremadnessproductions.net/Samples/Resize-Text/Sample.html
    http://www.meschrene.puremadnessproductions.net/Samples/Resize-Text/Sample.zip

Maybe you are looking for

  • Password for a startup

    Tell me please, what section Bios menu sets password for a startup? System board of MSI. Chipset - Intel 915 P Combo2 BIOS version -  W71401MS v.3.1 In the main BIOS menu exist the Set Password menu, the password is set ONLY entrance to the BIOS. In

  • Subreport not displayed when Run from SAP Business One

    We have a crystal report that displays a subreport when it is run from within the Crystal 2008 Designer but not when run from within SAP. Has anybody else seen this error? We have tried importing it into SAP and checking the connections of the report

  • Are the Mac and Windows forums for InDesign combined now or am I missing something?

    If they are I'm not so sure this is a good idea.

  • Error during the update

    Hi everyone. I got a big problem. I updated my iTouch 4 (32 GO) , and there was an error . And now, my ipod ask me to sync with iTunes, but Windows & iTunes doesn't recognize the ipod. I reboot my computer, iTunes, my iPod,  and nothing change ! Can

  • Migration Error - JTEAM please respond!

    Im trying to migrate rc1 to rc production..... Some of my pages work but am getting an application error on this page It is an Application error - no further information. When I remove the sWhereClause and the assignment of this sWhereClause, my page