Background image in extended awt.Button doesn't show.

Hi all
I have an applet that has only an awt.Button visible on the page. Because of layout requirements I need to style that button with a background image. I have extended the java.awt.Button like this:
     class ImageButton extends Button {
          public void paint(Graphics g) {
               super.paint(g);
               g.drawImage(getImage(getDocumentBase(), "../img/loadSertificate.jpg"),
                         0, 0, null);
     }and use the extended:
     public void init() {
          mSignButton = new ImageButton();
          mSignButton.setLocation(0, 0);
          Dimension appletSize = this.getSize();
          mSignButton.setSize(appletSize);
          mSignButton.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    signSelectedFile();
          this.setLayout(null);
          this.add(mSignButton);
     }Now everiting is ok but when the applet is loaded the background image doesn't show and only a plain gray button is visible. The interesting part is that the image does show after I click somewhere in the browser's window and later on it's always visible as expected.
Below is part from the log from the java console:
basic: Applet started
basic: Told clients applet is started
Loaded image: http://ip:8080/UserManagement/img/loadSertificate.jpg
network: Cache entry found [url: http://ip:8080/UserManagement/img/loadSertificate.jpg, version: null]
network: Connecting http://ip:8080/UserManagement/img/loadSertificate.jpg with proxy=DIRECT
network: Connecting http://ip:8080/UserManagement/img/loadSertificate.jpg with cookie "JSESSIONID=8A0936441BDA3215A10D9798742C4685"
network: CleanupThread used 39850 us
network: ResponseCode for http://ip:8080/UserManagement/img/loadSertificate.jpg : 304
network: Encoding for http://ip:8080/UserManagement/img/loadSertificate.jpg : null
network: Disconnect connection to http://ip:8080/UserManagement/img/loadSertificate.jpg
Loaded image: http://ip:8080/UserManagement/img/loadSertificate.jpgAny suggestions how to fix this issue?!
Edited by: factor5 on Nov 12, 2009 1:27 AM
Edited by: factor5 on Nov 12, 2009 1:28 AM

xmm sry but this was a forgotten repaint() :
          public void paint(Graphics g) {
               // call super's paint method
               super.paint(g);
               g.drawImage(getImage(getDocumentBase(), APPLET_BUTTON_IMAGE_URL),
                         0, 0, null);
               repaint();
          }Now it seems to work fine.
Edited by: factor5 on Nov 12, 2009 1:44 AM

Similar Messages

  • Interactive Button Doesn't Show in PDF

    I have created a button in InDesign (CS3) and when I convert into a PDF the button doesn't show in the PDF. I have made sure that the visible option is selected the button options. Am I missing somehting?
    HELP!!!

    Are you exporting or printing to PDF? You must export.
    You must also select the options for interactive content.
    What preset, if any are you using?

  • ITunes 10.5 and Win7 64bit: Airplay button doesn't show up. Please help!

    I am running Win7 and recently installed iTunes 10.5.
    Before I was using an older version of iTunes which allowed me to stream my music via airplay to my airport express, but I could not access iTunes-store with the old version of iTunes.
    Since I've updated, I can access the iTunes-store, but the the airplay button in iTunes has vanished. This is very disappointing.
    Does anyone know how to solve this problem?
    Thanks a lot!

    It's a bug with iTunes 10.4.0.80. If you copy and paste from some web browsers or an image editor then iTunes pastes in a transparent image of the same dimensions. This shows up black in the artwork panel at the bottom left or white in the get info art viewer.
    If you work with an image file stored on your computer you will get better results. Use the artwork box on the Info tab of the Get Info. dialog for multiple tracks to replace all existing images. With a single track you will need to delete the existing corrupt images from the Artwork tab first.
    tt2

  • Why does my volume buttons doesn't show when the Ipad is locked, Why does my volume buttons doesn't show when the Ipad is locked

    The volume buttons doesn't work when my ipad is locked but before the did worked I wanna know why they stoy working so suddenly

    So it doesn't show when I turn down or up my volume when it's locked?
    I'm checking my iPod and is also like this when it Locke it doesn't show when I'm turning it down or up

  • Video call button doesn't show up

    Trying to make a video call but the option isn't even showing up. Just says: video message, send photos , voice call and I'm. What in the world is going on..

    I'm surprised that the button shows up at all if you override the paint method.
    Why are you setting the location of the button in the paint method?
    Personnally, if I wanted to display a button and an image in the same applet, I'd:
    1) Use a Button in an Applet, not a JButton. I wouldn't mix Swing and plain AWT.
    2) create a new component (say, a Canvas subclass) to display the image. I'd override paint() in this new component only.
    3) add both the new component and the Button to the applet, in the constructor or init(), set the locations of these components there as well, probably just using a LayoutManager
    4) I wouldn't even use try/catch in paint(), but if I did, I wouldn't ignore the exceptions it catches.

  • MS Windows Media player Firefox plugin 1.0.0.8 is installed still after upgrade from FF 3.5. to FF4, but it does not work anymore on Windows 7. The player buttons doesn´t show up. However, it works on WinXP after the same upgrade.

    Windows 7 professional with Windows Media Player 11 and WMP plugin for Firefox 4 doesn´t work, but on WinXP it does work normally with the same plugin version after upgrade to FF4.

    Try http://forums.adobe.com/thread/892474

  • Push buttons doesn't show up in Appraisal template-(ESS,MSS)

    Hi SAP friends,
    I have template created with few sub-statuses and thus have created few push buttons to control the flow in ESS and MSS portal.
    However I do not see any pushbuttons (or radio buttons) in ESS/MSS.  Appreciate if you can guide me what all areas I was missing?  Do we need to do anything in portal or Iviews? I read somewhere in forum that we need to do some thing in Iviews, but I was not convinced with it. Appreciate your speedy suggestions as we are in critical stage of project.
    I have substatus created in In-Planning.
    I'm not using In-planning status but using sub-status.  Here is how I have mapped
    Status flow at template level:
    Outbout status - "In-PLanning"
    Outbout substatus : Enter Objectives & Goals(Employee level)
    PUSH BUTTON  - Submit for Mgr review
    Person Authorized - Aprraises
    Target status : In- PLanning
    Target substus - Manager Review

    Hi
    I think u are trying to go to previous status from sub status. From In Preparation you can come to In planning or the sub status of in planning.
    Thanks & regards,
    Vikas

  • Downgraded to 3.6 and now there is a "background" image to the sides on websites that showed up in 4 and now is still there. How do I get rid of the side image and get the site to look like it once did??

    Often sites display the site in the middle with filler to the side. Now there is an image there that doesnt show up on Opera but now it does on firefox

    Thanks C for taking the time to help!
    I did safe mode as you suggested and things were set to the default theme.
    It still didn't display like it did before I "upgraded".
    Let me ask this another way. Looking at this very site, the whole website is displayed in the center of the screen and the sides are blank. Meaning that there is a bunch of wasted space. How do I configure firefox so it fills the screen?? If I could see just the middle portion that is how it used to display things.
    Here is what I mean:
    [space space WEBSITE space space]
    I just want to see:
    [W E B S I T E]
    And only that filling the screen.
    Thanks again for the help!

  • How do you add an image to the preview that doesn't show up in the live site?

    Is it possible to add an image that would take the place of " <> " ?

    No this is how it's done. This answer was provided by Nthsecret
    1) I create an image of my widget preview (ex. with photoshop);
    2) I add an image in a server or ftp;
    3) I add the image into file .mucow in this mode:
          <pageItemPosterHTML>
                <![CDATA[
                     <div><img src="YOUR_IMAGE" style=" height: HEIGHT_IN_PX; width: WIDTH_IN_PX;"></div>
                ]]>
          </pageItemPosterHTML>
         <pageItemHTML>
                <![CDATA[
                    <div></div>
                ]]>
          </pageItemHTML>

  • Extended partition but doesn't show in My Computer

    Extended an iSCSI mounted disk from 500GB to 750GB in Server 2008 R2 Standard.  Saw the larger disk in Disk Management and extended the partition successfully.  Ran Chkdsk on the new drive and it shows the correct total, used, and free space on
    the drive.  However, when I open My Computer the drive still shows the same old size.
    This is a physical HP server, iscsi drive is from a Netapp.
    Things I've tried but didn't work:
    1.  Diskpart and the extend filesystem command (http://support.microsoft.com/kb/832316)
    2.  Growing the disk by 1-50GB and re-extending the partition
    3.  Made funny faces
    I've seen this before in Server 2008 R2 on a VM but never on a physical machine.  Usually growing the disk and re-extending the parition has worked for me but not in this case.
    Chkdsk results:
    Windows has checked the file system and found no problems.
     805206015 KB total disk space.
     470081600 KB in 518767 files.
        250644 KB in 100413 indexes.
             0 KB in bad sectors.
        722479 KB in use by the system.
         65536 KB occupied by the log file.
     334151292 KB available on disk.

    Wouldn't a reboot reconnect the iSCSI drive?  If not, how would one do that?
    Can't imagine it would be a Netapp issue as it shows correctly in Disk Management and CHKDSK.  Perhaps there is a registry value that didn't get changed during the extend?  I can try connecting it to another computer.
    You would simply open iSCSI Initiator from start > administrative tools. Disconnect and reconnect the drive.
    Steve Kline
    Microsoft Certified IT Professional: Server Administrator
    Microsoft Certified Technology Specialist: Active Directory, Network Infrastructure, Application Platform, Windows 7
    Microsoft Certified Product Specialist & Network Product Specialist
    Red Hat Certified System Administrator
    Microsoft® Community Contributor Award 2011
    All opinions expressed on my own behalf and not that of my company.
    This posting is "as is" without warranties and confers no rights.

  • The X close button doesn't show on Tabs in 3.6.3. How do I get them back?

    The X close button stopped showing on Tabs when I upgraded to version 3.6.3. How do I get them back?
    == This happened ==
    Every time Firefox opened
    == latest version 3.6.3 downloaded on May 28th - 29th..

    I had the home page set to "about:blank" when I noticed that the x was missing. I then clicked on "Restore to Default", restarted and then selected "Show a blank page" - Restarted again and this time it worked, except that there is no x when there is only one tab. As soon as a second tab opens, an x suddenly appears on all the tabs. Keep in mind that I also updated the Walnut theme and all other add-ons. Not entirely happy with this niggle, but I can live with it. Version 3.6.3 is faster and that makes up for it.

  • The "option" button doesn't show up on Mac OS X install

    My hardrive died in original Macbook Pro. Got a SSD 840 pro 256gb and 8gb of ram.
    i installed the disk that came originally with Pro and procced to install.
    whe i reach the " select destinaion " screen nothing shows up in the main box area. And the Option in bottom left corner is un clickable.
    WHY is this!!???

    Welcome to Apple Support Communities
    Did you format the SSD? Remember that it must be formatted in order to install an operating system, so close the Mac OS X installer, open Disk Utility and format it > http://pondini.org/OSX/DU1.html

  • Problem placing buttons on top of a background image

    My knowledge of Java isn't the greatest and I am currently having problems placing buttons on top of a background image within a JApplet (this is also my first encounter with Applets).
    I'm using a Card Layout in order to display a series of different screens upon request.
    The first card is used as a Splash Screen which is displayed for 5 seconds before changing to the Main Menu card.
    When the Main Menu card is called the background image is not shown but the button is.
    While the Applet is running no errors are shown in the console.
    Full source code can be seen below;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    // First extend JApplet
    public class WOT extends JApplet {
         //--------------- Variables are declared here -----------------
         private CardLayout contentCardLayout = new CardLayout();  // declare CardLayout
         private Container contentContain;     // declare content Container
         private JPanel contentCard, splashScreen, mainMenu, menuImage; // declare content Panels
         private JLabel splash, menu, map; // declare image labels
         private ImageIcon mapBtn; // declare ImageIcons
         private JButton mapOption; // declare option Buttons
         private Timer timer; // declare Timer
         private ActionListener actionListener, mapOptionListener; // declare ActionListener
    //--------------- Initialise Applet -----------------
      public void init() {
         //--------------- Set-up Card Layout -----------------
         contentCard = new JPanel(contentCardLayout); // assign card panels to CardLayout
         //--------------- Splash Screen -----------------
         splashScreen = new JPanel();
         splash = new JLabel(new ImageIcon(getClass().getResource("img/bg.gif")));
         splashScreen.add(splash);
         splashScreen.setSize(600,800);
         splashScreen.setLocation(0,0);
    //--------------- "View Map" Option Button -----------------
         mapBtn = new ImageIcon(getClass().getResource("img/map.gif"));
         mapOption = new JButton(mapBtn);
         mapOption.setBorder(null);
         mapOption.setContentAreaFilled(false);
         mapOption.setSize(150,66);
         mapOption.setLocation(150,450);
         mapOption.setOpaque(false);
         mapOption.setVisible(true);
    //--------------- Main Menu Screen -----------------
         //menuImage = new JPanel(null);
         //menuImage.add(mainMenu);
         //menuImage.setLocation(0,0);
         mainMenu = new JPanel(null);
         menu = new JLabel(new ImageIcon(getClass().getResource("img/menu.gif")));
         menu.setLocation(0,0);
         mainMenu.add(menu);
         //mainMenu.setBackground(Color.WHITE);
         mainMenu.setLocation(0,0);
         mainMenu.setOpaque(false);
         //mainMenu.setSize(150,66);
         mainMenu.add(mapOption);
         //--------------- Map Image Screen -----------------
         map = new JLabel(new ImageIcon(getClass().getResource("img/map.gif")));
         //--------------- Add Cards to CardLayout Panel -----------------
        contentCard.add(splashScreen, "Splash Screen");
         contentCard.add(mainMenu, "Main Menu");
         contentCard.add(map, "Map Image");
    //--------------- Set-up container -----------------
          contentContain = getContentPane(); // set container as content pane
          contentContain.setBackground(Color.WHITE); // set container background colour
           contentContain.setLocation(0,0);
           contentContain.setSize(600,800);
          contentContain.setLayout(new FlowLayout()); // set container layout
           contentContain.add(contentCard);  // cards added
           //--------------- Timer Action Listener -----------------
           actionListener = new ActionListener()
                    public void actionPerformed(ActionEvent actionEvent)
                             //--------------- Show Main Menu Card -----------------
                             contentCardLayout.show(contentCard, "Main Menu");
         //--------------- Map Option Button Action Listener -----------------
           mapOptionListener = new ActionListener()
                    public void actionPerformed(ActionEvent actionEvent)
                             //--------------- Show Main Menu Card -----------------
                             contentCardLayout.show(contentCard, "Map Image");
         //--------------- Timer -----------------               
         timer = new Timer(5000, actionListener);
         timer.start();
         timer.setRepeats(false);
    }Any help would be much appreciated!
    Edited by: bex1984 on May 18, 2008 6:31 AM

    1) When posting here, please use fewer comments. The comments that you have don't help folks who know Java read and understand your program and in fact hinder this ability, which makes it less likely that someone will in fact read your code and help you -- something you definitely don't want to have happen! Instead, strive to make your variable and method names as logical and self-commenting as possible, and use comments judiciously and a bit more sparingly.
    2) Try to use more methods and even classes to "divide and conquer".
    3) To create a panel with a background image that can hold buttons and such, you should create an object that overrides JPanel and has a paintComponent override method within it that draws your image using the graphics object's drawImage(...) method
    For instance:
    an image jpanel:
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.net.URISyntaxException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    public class BackgroundImage
        // **** this will have to be changed for your program:
        private static final String IMAGE_PATH = "../../m02/a/images/Forest.jpg";
        private BufferedImage myImage = null;
        private JPanel imagePanel = new JPanel()
            @Override
            protected void paintComponent(Graphics g)
            {   // *** here is where I draw my image
                super.paintComponent(g);  // **** don't forget this!
                if (myImage != null)
                    g.drawImage(myImage, 0, 0, this);
        public BackgroundImage()
            imagePanel.setPreferredSize(new Dimension(600, 450));
            imagePanel.add(new JButton("Foobars Rule!"));
            try
                myImage = createImage(IMAGE_PATH);
            catch (IOException e)
                e.printStackTrace();
            catch (URISyntaxException e)
                e.printStackTrace();
        private BufferedImage createImage(String path) throws IOException,
                URISyntaxException
            URL imageURL = getClass().getResource(path);
            if (imageURL != null)
                return ImageIO.read(new File(imageURL.toURI()));
            else
                return null;
        public JPanel getImagePanel()
            return imagePanel;
    }and an applet that uses it:
    import java.lang.reflect.InvocationTargetException;
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    public class BackgrndImageApplet extends JApplet
        @Override
        public void init()
            try
                SwingUtilities.invokeAndWait(new Runnable()
                    @Override
                    public void run()
                        getContentPane().add(new BackgroundImage().getImagePanel());
            catch (InterruptedException e)
                e.printStackTrace();
            catch (InvocationTargetException e)
                e.printStackTrace();
    }

  • A page from a template doesn't inherit a background image.

    I created a template and gave it a background image, tested in the browser, and it worked fine. Then I made a page from that template and it simply didn't show the background image, even though all the other components showed up properly. Any ideas as to what the problem may be?

    Some things to check:
    1) Did you define a local site folder in DW before starting your project?
    2) When you made a page from the Template, did you use  File > New > Page from Template?
    3) Is your background image saved for the web as RBG and not CMYK?
    4) In your CSS code, what is the path to your background image?
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb

  • Problem with Background image and JFrame

    Hi there!
    I've the following problem:
    I created a JFrame with an integrated JPanel. In this JFrame I display a background image. Therefore I've used my own contentPane:
    public class MContentPane extends JComponent{
    private Image backgroundImage = null;
    public MContentPane() {
    super();
    * Returns the background image
    * @return Background image
    public Image getBackgroundImage() {
    return backgroundImage;
    * Sets the background image
    * @param backgroundImage Background image
    public void setBackgroundImage(Image backgroundImage) {
    this.backgroundImage = backgroundImage;
    * Overrides the painting to display a background image
    protected void paintComponent(Graphics g) {
    if (isOpaque()) {
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    if (backgroundImage != null) {
    g.drawImage(backgroundImage,0,0,this);
    super.paintComponent(g);
    Now the background image displays correct. But as soon as I click on some combobox that is placed within the integrated JPanel I see fractals of the opened combobox on the background. When I minimize
    the Frame they disappear. Sometimes though I get also some fractals when resizing the JFrame.
    It seems there is some problem with the redrawing of the background e.g. it doesn't get redrawn as often as it should be!?
    Could anyone give me some hint, on how to achieve a clear background after clicking some combobox?
    Thx in advance

    I still prefer using a border to draw a background image:
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.border.*;
    public class CentredBackgroundBorder implements Border {
        private final BufferedImage image;
        public CentredBackgroundBorder(BufferedImage image) {
            this.image = image;
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            int x0 = x + (width-image.getWidth())/2;
            int y0 = y + (height-image.getHeight())/2;
            g. drawImage(image, x0, y0, null);
        public Insets getBorderInsets(Component c) {
            return new Insets(0,0,0,0);
        public boolean isBorderOpaque() {
            return true;
    }And here is a demo where I load the background image asynchronously, so that I can launch the GUI before the image is done loading. Warning: you may find the image disturbing...
    import java.awt.*;
    import java.io.*;
    import java.net.URL;
    import javax.imageio.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class BackgroundBorderExample {
        public static void main(String[] args) throws IOException {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame f = new JFrame("BackgroundBorderExample");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JTextArea area = new JTextArea(24,80);
            area.setForeground(Color.WHITE);
            area.setOpaque(false);
            area.read(new FileReader(new File("BackgroundBorderExample.java")), null);
            final JScrollPane sp = new JScrollPane(area);
            sp.setBackground(Color.BLACK);
            sp.getViewport().setOpaque(false);
            f.getContentPane().add(sp);
            f.setSize(600,400);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            String url = "http://today.java.net/jag/bio/JagHeadshot.jpg";
            final Border bkgrnd = new CentredBackgroundBorder(ImageIO.read(new URL(url)));
            Runnable r = new Runnable() {
                public void run() {
                    sp.setViewportBorder(bkgrnd);
                    sp.repaint();
            SwingUtilities.invokeLater(r);
    }

Maybe you are looking for

  • Can't save file in UTF-8 encoding

    Hi, I've read everything I can find on this subject, from these forums to Google to newsgroups. Still no success. I am simply trying to save a file in UTF-8 format. This code depicts the methods I'm using: File file = new File("myFile"); FileOutputSt

  • ANT script genrated error: package javax.servlet does not exist

    Hi there, I am running ANT and confronted this message:     [javac] Compiling 1 source file to C:\eclipseProjects\tomcat_test     [javac] C:\eclipseProjects\tomcat_test\WEB-INF\src\WebTest.java:4: package javax.servlet does not exist     [javac] impo

  • Apple service toolkit 1.5.9 required

    Dear sir, I have lost the apple service toolkit V1.5.9 file so, i have required it.In gsx showing new version AST 1.5.10 download link, kindly requested to give the exact link for downloading it. I am waiting for your response as soon as . Thanks, Di

  • Issue with Adobe Prox shutting down when combining files

    I am having an issue with Adobe.  I can open files no problem but when I click to combine multiple files into one pdf, as soon as I try to add the files, it automatically shuts down?

  • After resseting my ipod, why wont any of my downloaded apps open?

    I just got my ipod touch 5.0.1 yesterday, and I downloaded 11 apps, from the app store. When ever I touch an app, it looks like it's going to go into it, but it does nothing. I payed 15$ for these apps, and none work. I tryed to re download them all,