Personalize jButton

I wish to add 2 icons to a jButton, fit these images to the full size of the button and add a number to these buttons which will be visible over the images (and not as text).
I have just started programming in java and all attempts to find the equivalent commands from c# have failed. Any info would be greatly appreciated.
If it isn't possible to personalize a jButton in this way alternative methods (maybe using a JPanel instead) would also be helpful.

Thanks for your reply,
I want the text on the jbuttons to change each time
the frame is launched, and randomly selects a word
from a list of words, and displays it as the text on
the jbutton.
Does anybody know a way to do this.
Thanks in anticipation
ZaggaDo you want us to just write the whole program for you?

Similar Messages

  • Resized animated gif ImageIcon not working properly with JButton etc.

    The problem is that when I resize an ImageIcon representing an animated gif and place it on a Jbutton, JToggelButton or JLabel, in some cases the image does not show or does not animate. More precicely, depending on the specific image file, the image shows always, most of the time or sometimes. Images which are susceptible to not showing often do not animate when showing. Moving over or clicking with the mouse on the AbstractButton instance while the frame is supposed to updated causes the image to disappear (even when viewing the non-animating image that sometimes appears). No errors are thrown.
    Here some example code: (compiled with Java 6.0 compliance)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test
         public static void main(String[] args)
              new Test();
         static final int  IMAGES        = 3;
         JButton[]           buttons       = new JButton[IMAGES];
         JButton             toggleButton  = new JButton("Toggle scaling");
         boolean            doScale       = true;
         public Test()
              JFrame f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel p = new JPanel(new GridLayout(1, IMAGES));
              for (int i = 0; i < IMAGES; i++)
                   p.add(this.buttons[i] = new JButton());
              f.add(p, BorderLayout.CENTER);
              f.add(this.toggleButton, BorderLayout.SOUTH);
              this.toggleButton.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e)
                        Test.this.refresh();
              f.setSize(600, 300);
              f.setVisible(true);
              this.refresh();
         public void refresh()
              this.doScale = !this.doScale;
              for (int i = 0; i < IMAGES; i++)
                   ImageIcon image = new ImageIcon(i + ".gif");
                   if (this.doScale)
                        image = new ImageIcon(image.getImage().getScaledInstance(180, 180, Image.SCALE_AREA_AVERAGING));
                   image.setImageObserver(this.buttons);
                   this.buttons[i].setIcon(image);
                   this.buttons[i].setSelectedIcon(image);
                   this.buttons[i].setDisabledIcon(image);
                   this.buttons[i].setDisabledSelectedIcon(image);
                   this.buttons[i].setRolloverIcon(image);
                   this.buttons[i].setRolloverSelectedIcon(image);
                   this.buttons[i].setPressedIcon(image);
    Download the gif images here:
    http://djmadz.com/zombie/0.gif
    http://djmadz.com/zombie/1.gif
    http://djmadz.com/zombie/2.gif
    When you press the "Toggle scaling"button it switches between unresized (properly working) and resized instances of three of my gif images. Notice that the left image almost never appears, the middle image always, and the right image most of the time. The right image seems to (almost) never animate. When you click on the left image (when visble) it disappears only when the backend is updating the animation (between those two frames with a long delay)
    Why are the original ImageIcon and the resized ImageIcon behaving differently? Are they differently organized internally?
    Is there any chance my way of resizing might be wrong?

    It does work, however I refuse to use SCALE_REPLICATE for my application because resizing images is butt ugly, whether scaling up or down. Could there be a clue in the rescaling implementations, which I can override?
    Maybe is there a way that I can check if an image is a multi-frame animation and set the scaling algorithm accordingly?
    Message was edited by:
    Zom-B

  • Report personalization issue..

    Hi Experts,
    We have published our few reports which are orignially created in Query designer in our BW portal using the WAD iviews. We have a issue that when we choose "Personalize Web application"  for a report then same reports opens up every time even if we choose to open different report.
    Can any one please suggest why it is happening!
    Thanks
    VV

    Please see below link if you need to remove the personilsation:
    Page not displaying iviews
    It works on the same priciple as your issue.
    Thanks,
    Em

  • How to find the user who did the personalization?

    Hi All,
    Is there a way to find out which user has done personalizations in a given OA page? For e.g. if a user has done personalization for hiding a text bean in a page, I want to find out that user's name by passing the page name to a script?
    Even if not possible through script, if there is any other way to achieve this, please let me know.
    Regards,
    Pradeep

    I dont think it is possible. The LAST_UPDATED_BY column in JDR_PATHS is always set to INTERNAL.
    Thanks
    Pradeep

  • In Design CS2 won't accept serial number during "Personalization" In Design

    Re: InDesignCS2 rejects the serial number provided for CS2 special "no-activation" versions.
    I am having an identical set of issues as outlined in the above discussion but I am using Windows 7.
    My hard disk died and I am simply trying to get back up to speed with the new one. I have Creative Suite 2 Premium.  Following the special instructions for moving certain files so that I wouldn't have the Insert Disk 2 problems I managed to get PhotoShop actuvated and running. However, I am unable to "personalize" InDesign because the system does not like the serial number.  I have tried the one that came on the original box and the one that was on the link I used to download the programs. Both with and without the hyphens.
    I have also been unable to uninstall InDesign and start over as the wizard was interrupted just as it was described above.
    I have followed the instructions on the link you provided to manually remove CS2:  Manually remove Adobe Creative Suite 2.x | Windows  Including attempting to uninstall Creative Suite.  However, Adobe InDesign CS2, Adobe Illustrator CS2, and Adobe SVG Viewer 3 still appear in the list of programs and for some reason cannot be uninstalled using the control panel.
    In looking at the files that are still on the computer I see a folder C:\Creative Suite CS2. It has folders in it for PhotoShop, Illustrator, and Version Cue plus some other stuff. I was able to delete each of the files individually. but when I attempt to delete Illustrator, I get an error message saying  that it can't be deleted  because a folder or file is open in another application. When I attempt to uninstall that one using the control panel I get a message saying the remover was interrupted before it could finish.
    I haven't even gotten to the part of the instructions where you remove things from the registry!
    Any thoughts on where to go from here?
    Thanks,
    E.

    You need to see the following for CS2 installation:
    Error: Activation Server Unavailable | CS2, Acrobat 7, Audition 3 -
    http://helpx.adobe.com/x-productkb/policy-pricing/creative-suite-2-activation-end-life.htm l

  • Unable to see the personalization link on any page

    Hi,
    I am unable to see the personalization link on any of my pages (not even on login page).
    I am setting the profile option value to "Yes" for the profile option
    FND: Personalization Region Link Enabled
    Also I have bounced the Apache.
    Please help me as I am stuck due to this.
    Thanks,
    Anoop

    Did you enabled the profile option Personalize Self-Service Defn (FND_CUSTOM_OA_DEFINTION) .It must be set to Yes.
    Abhay

  • Unable to  trace JButton event

    hello there,
    iam creating a JButton on which iam setting an imageicon .
    instead of the image path to the constructor of jbutton iam passing the
    byte array of that image.
    now the problem is when i click on that button, iam unable to trace in the actionperformed method that this particular button was clicked.
    any help in this regard is mostly appreciated.
    bye

    sorry. a small correction to the above sentence
    iam creating that image through the byte array which is passed to the constructor of the ImageIcon. now this imageicon object is passed to the constructor of the jbutton.

  • Getting the label of a JButton in a for loop

    hi,
    I doing a project for my course at the minute and im in need of a bit of help. I have set up 1-d array of buttons and i have layed them out using a for loop. I have also added an annoymous action listener to each button in the loop. It looks something lke this:
    b = new JButton[43];
    for (int i=1; i<43; i++)
    b[i] = new JButton(" ");
    b.addActionListener(
    new ActionListener()
    public void actionPerformed(ActionEvent e)
              System.out.println("..........");
    }); // addActionListener
    } // for
    I want the "System.out.println( ..." line, to print out the "i" number of the button that was pressed but i cannot figure out how to do it. I cannot put "System.out.println(" "+i);" as it wont recognise i as it is not inside the for loop. Does anyone have any suggestions?
    Thanks!!

    class ButtonExample extends JFrame implements ActionListener{The OP wanted to have anonymous listeners, not a subclassed JFrame
    listening to the buttons. I don't know if the following is the best design,
    since the poster has revealed so little, but here is how to pass the
    loop index to an anonymous class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ButtonExample {
        private JButton[] buttons = new JButton[24];
        public JPanel createGUI() {
            JPanel gui = new JPanel(new GridLayout(6,  4));
            for(int i=0; i<buttons.length; i++) {
                final int ii = i; //!! !
                buttons[i] = new JButton("button #" + i);
                buttons.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent evt) {
    System.out.println("number " + ii);
    gui.add(buttons[i]);
    return gui;
    public static void main(String[] args) {
    ButtonExample app = new ButtonExample();
    JPanel gui = app.createGUI();
    JFrame f = new JFrame("ButtonExample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(gui);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);

  • Personalization is not getting deleted in R12

    Hey OAF gurus,
    I have extended a standard CO in R12 and through personalization I attached my custom CO to that standard page .
    But due to some reason page is erroring out before rendering itself .So, now I want to delete that personalization .
    I tried with jdr_utils.deletedocument but it still pointing to my custom CO .
    Even I set the profile "Disable Self-Service Personal" as yes and then navigated to that page after that I tried to remove the custom CO by clicking personalize page but after clicking apply its still pointing to my custom CO.
    Please help me on this .
    Even when I am executing jdr_utils.listcustomizations its not showing anything which means that there is no personalization . But I am still getting the error which is pointing to my custom CO.

    Thanks sushant/Moorthy.
    I am able to delete the personalization .
    But when I am attaching I custom CO then I am getting the below error :-
    oracle.apps.fnd.framework.OAException: oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.classloader.util.AnnotatedNoClassDefFoundError, msg=
    *     Missing class: who.oracle.apps.ap.payments.psr.webui.APExtension (wrong name: who.oracle.apps.ap.payments.webui.APExtension)*
    *     Dependent class: who.oracle.apps.ap.payments.psr.webui.APExtension*
    *     Loader: oacore.root:0.0.0*
    *     Code-Source: /u02/apr12dev/r12dev/apps/apps_st/comn/java/classes/*
    *     Configuration: <library> in /u02/apr12dev/r12dev/apps/apps_st/comn/webapps/oacore/*
    The missing class is not available from any code-source or loader in the system.
    *     at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:912)*
    *     at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:888)*
    *     at OAErrorPage.jspService(_OAErrorPage.java:221)*
    *     at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)*
    *     at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:390)*
    *     at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)*
    *     at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)*
    *     at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)*
    *     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:734)*
    *     at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)*
    *     at com.evermind.server.http.ServletRequestDispatcher.unprivileged_forward(ServletRequestDispatcher.java:280)*
    *     at com.evermind.server.http.ServletRequestDispatcher.access$100(ServletRequestDispatcher.java:68)*
    *     at com.evermind.server.http.ServletRequestDispatcher$2.oc4jRun(ServletRequestDispatcher.java:214)*
    *     at oracle.oc4j.security.OC4JSecurity.doPrivileged(OC4JSecurity.java:284)*
    *     at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:219)*
    *     at com.evermind.server.http.EvermindPageContext.handlePageThrowable(EvermindPageContext.java:871)*
    *     at com.evermind.server.http.EvermindPageContext.handlePageException(EvermindPageContext.java:816)*
    *     at OA.jspService(_OA.java:256)*
    *     at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)*
    *     at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:390)*
    *     at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)*
    *     at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)*
    *     at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)*
    *     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:734)*
    *     at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)*
    *     at com.evermind.server.http.ServletRequestDispatcher.unprivileged_forward(ServletRequestDispatcher.java:280)*
    *     at com.evermind.server.http.ServletRequestDispatcher.access$100(ServletRequestDispatcher.java:68)*
    *     at com.evermind.server.http.ServletRequestDispatcher$2.oc4jRun(ServletRequestDispatcher.java:214)*
    *     at oracle.oc4j.security.OC4JSecurity.doPrivileged(OC4JSecurity.java:284)*
    *     at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:219)*
    *     at com.evermind.server.http.EvermindPageContext.forward(EvermindPageContext.java:395)*
    *     at OA.jspService(_OA.java:221)*
    *     at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)*
    *     at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:390)*
    *     at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)*
    *     at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)*
    *     at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)*
    *     at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)*
    *     at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)*
    *     at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)*
    *     at oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:318)*
    *     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:642)*
    *     at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)*
    *     at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:908)*
    *     at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:458)*
    *     at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:313)*
    *     at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:199)*
    *     at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)*
    *     at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)*
    *     at java.lang.Thread.run(Thread.java:619)*
    *## Detail 0 ##*
    oracle.classloader.util.AnnotatedNoClassDefFoundError:
    *     Missing class: who.oracle.apps.ap.payments.psr.webui.APExtension (wrong name: who.oracle.apps.ap.payments.webui.APExtension)*
    *     Dependent class: who.oracle.apps.ap.payments.psr.webui.APExtension*
    *     Loader: oacore.root:0.0.0*
    *     Code-Source: /u02/apr12dev/r12dev/apps/apps_st/comn/java/classes/*
    *     Configuration: <library> in /u02/apr12dev/r12dev/apps/apps_st/comn/webapps/oacore/*
    The missing class is not available from any code-source or loader in the system.
    *     at oracle.classloader.PolicyClassLoader.defineClass(PolicyClassLoader.java:2401)*
    *     at oracle.classloader.PolicyClassLoader.findLocalClass(PolicyClassLoader.java:1539)*
    *     at oracle.classloader.SearchPolicy$FindLocal.getClass(SearchPolicy.java:226)*
    *     at oracle.classloader.SearchSequence.getClass(SearchSequence.java:119)*
    *     at oracle.classloader.SearchPolicy.loadClass(SearchPolicy.java:852)*
    *     at oracle.classloader.PolicyClassLoader.askParentForClass(PolicyClassLoader.java:1355)*
    *     at oracle.classloader.SearchPolicy$AskParent.getClass(SearchPolicy.java:72)*
    *     at oracle.classloader.SearchSequence.getClass(SearchSequence.java:119)*
    *     at oracle.classloader.PolicyClassLoader.internalLoadClass(PolicyClassLoader.java:1721)*
    *     at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1682)*
    *     at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1667)*
    *     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)*
    *     at java.lang.Class.forName0(Native Method)*
    *     at java.lang.Class.forName(Class.java:247)*
    *     at oracle.jbo.common.java2.JDK2ClassLoader.loadClassForName(JDK2ClassLoader.java:38)*
    *     at oracle.jbo.common.JBOClass.forName(JBOClass.java:164)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanHelper.getController(OAWebBeanHelper.java:1871)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:572)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:252)*
    *     at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processRequest(OAPageLayoutHelper.java:1182)*
    *     at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processRequest(OAPageLayoutBean.java:1569)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:968)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:935)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:659)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:252)*
    *     at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processRequest(OAFormBean.java:385)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:968)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:935)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:659)*
    *     at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:252)*
    *     at oracle.apps.fnd.framework.webui.beans.OABodyBean.processRequest(OABodyBean.java:353)*
    *     at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(OAPageBean.java:2607)*
    *     at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1940)*
    *     at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:543)*
    *     at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:431)*
    *     at OA.jspService(_OA.java:212)*
    *     at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)*
    *     at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:390)*
    *     at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)*
    *     at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)*
    *     at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)*
    *     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:734)*
    *     at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)*
    *     at com.evermind.server.http.ServletRequestDispatcher.unprivileged_forward(ServletRequestDispatcher.java:280)*
    *     at com.evermind.server.http.ServletRequestDispatcher.access$100(ServletRequestDispatcher.java:68)*
    *     at com.evermind.server.http.ServletRequestDispatcher$2.oc4jRun(ServletRequestDispatcher.java:214)*
    *     at oracle.oc4j.security.OC4JSecurity.doPrivileged(OC4JSecurity.java:284)*
    *     at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:219)*
    *     at com.evermind.server.http.EvermindPageContext.forward(EvermindPageContext.java:395)*
    *     at OA.jspService(_OA.java:221)*
    *     at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)*
    *     at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:390)*
    *     at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)*
    *     at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)*
    *     at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)*
    *     at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)*
    *     at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)*
    *     at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)*
    *     at oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:318)*
    *     at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:642)*
    *     at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)*
    *     at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:908)*
    *     at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:458)*
    *     at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:313)*
    *     at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:199)*
    *     at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)*
    *     at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)*
    *     at java.lang.Thread.run(Thread.java:619)*
    I placed my custom CO file in server at below path :-
    who.oracle.apps.ap.payments.psr.webui.APExtension but error file says wrong path who.oracle.apps.ap.payments.webui.APExtension

  • How to display a JPanel of JButtons on ImagePanel?

    Hi
    From the Swing Hacks examples, I can display a JButton on an ImagePanel no problem. But when I put this JButton in JPanel, then add the JPanel to the ImagePanel, the JPanel with the JButton is not displayed.
    Can someone please explain why this is?
    Here is the ImagePanel code:
    import java.awt.*;
    import javax.swing.*;
    public class ImagePanel extends JPanel {
        private Image img;
        public ImagePanel(String img) {
            this(new ImageIcon(img).getImage());
        public ImagePanel(Image img) {
            this.img = img;
            Dimension size = new Dimension(img.getWidth(null),img.getHeight(null));
            setPreferredSize(size);
            setMinimumSize(size);
            setMaximumSize(size);
            setSize(size);
            setLayout(null);
        public void paintComponent(Graphics g) {
            g.drawImage(img,0,0,null);
    }And here is the code to add a JButton to a JPanel, then add the JPanel to the ImagePanel:
    import javax.swing.*;
    import java.awt.event.*;
    public class ImageTest {
        public static void main(String[] args) {
           ImagePanel panel = new ImagePanel(new ImageIcon("images/background.png").getImage());
           JPanel buttonPanel = new JPanel()       
            JButton button = new JButton("Button");
            buttonPanel.add(button);
           JFrame frame = new JFrame("Hack #XX: Image Components");
            frame.getContentPane().add(button);    // WORKS!
            //frame.getContentPane().add(buttonPanel);   // NO BUTTON IS DISPLAYED???
           frame.pack();
            frame.setVisible(true);
    }Thanks

    setLayout(null);When you use a null layout then you are responsible for setting the size and location of any component added to the panel. The default location is (0,0) so thats ok, but the default size of the button panel is also (0,0) which is why nothing get painted.
    Don't use a null layout. Let the layout manager layout any component added to it.
    Also, I would override the getPreferredSize() method of your ImagePanel to return the size of the image, instead of setting the preferred size in the constructor.

  • How do i use jbutton for mutiple frames(2frames)???

    im an creating a movie database program and i have a problem with the jButtons on my second frame i dont know how to make them work when clicked on. i managed to make the jButtons work on my first frame but not on the second....
    here is that code so far----
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    * real2.java
    * Created on December 7, 2007, 9:00 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    * @author J
    public class real2 extends JPanel  implements ActionListener{
        private JButton addnew;
        private JButton help;
        private JButton exit;
        private JFrame frame1;
        private JButton save;
        private JButton cancel;
        private JButton save2;
        private JLabel moviename;
        private JTextField moviename2;
        private JLabel director;
        private JTextField director2;
        private JLabel year;
        private JTextField year2;
        private JLabel genre;
        private JTextField genre2;
        private JLabel plot;
        private JTextField plot2;
        private JLabel rating;
        private JTextField rating2;
        /** Creates a new instance of real2 */
        public real2() {
            super(new GridBagLayout());
            //Create the Buttons.
            addnew = new JButton("Add New");
            addnew.addActionListener(this);
            addnew.setMnemonic(KeyEvent.VK_E);
            addnew.setActionCommand("Add New");
            help = new JButton("Help");
            help.addActionListener(this);
            help.setActionCommand("Help");
            exit = new JButton("Exit");
            exit.addActionListener(this);
            exit.setActionCommand("Exit");
           String[] columnNames = {"First Name",
                                    "Last Name",
                                    "Sport",
                                    "# of Years",
                                    "Vegetarian"};
            Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)}
            final JTable table = new JTable(data, columnNames);
            table.setPreferredScrollableViewportSize(new Dimension(600, 100));
            table.setFillsViewportHeight(true);
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            add(scrollPane);
            GridBagConstraints c = new GridBagConstraints();
            c.weightx = 1;
            c.gridx = 0;
            c.gridy = 1;
            add(addnew, c);
            c.gridx = 0;
            c.gridy = 2;
            add(help, c);
            c.gridx = 0;
            c.gridy = 3;
            add(exit, c);
        public static void addComponentsToPane(Container pane){
            pane.setLayout(null);
            //creating the components for the new frame
            JButton save = new JButton("Save");
            JButton save2 = new JButton("Save and add another");
            JButton cancel = new JButton("Cancel");
            JLabel moviename= new JLabel("Movie Name");
            JTextField moviename2 = new JTextField(8);
            JLabel director = new JLabel("Director");
            JTextField director2 = new JTextField(8);
            JLabel genre = new JLabel("Genre");
            JTextField genre2 = new JTextField(8);
            JLabel year = new JLabel("year");
            JTextField year2 = new JTextField(8);
            JLabel plot = new JLabel("Plot");
            JTextField plot2 = new JTextField(8);
            JLabel rating = new JLabel("Rating(of 10)");
            JTextField rating2 = new JTextField(8);
            //adding components to new frame
            pane.add(save);
            pane.add(save2);
            pane.add(cancel);
            pane.add(moviename);
            pane.add(moviename2);
            pane.add(director);
            pane.add(director2);
            pane.add(genre);
            pane.add(genre2);
            pane.add(year);
            pane.add(year2);
            pane.add(plot);
            pane.add(plot2);
            pane.add(rating);
            pane.add(rating2);
            //setting positions of components for new frame
                Insets insets = pane.getInsets();
                Dimension size = save.getPreferredSize();
                save.setBounds(100 , 50 ,
                         size.width, size.height);
                 size = save2.getPreferredSize();
                save2.setBounds(200 , 50 ,
                         size.width, size.height);
                 size = cancel.getPreferredSize();
                cancel.setBounds(400 , 50 ,
                         size.width, size.height);
                 size = moviename.getPreferredSize();
                moviename.setBounds(100 , 100 ,
                         size.width, size.height);
                size = moviename2.getPreferredSize();
                moviename2.setBounds(200 , 100 ,
                         size.width, size.height);
                 size = director.getPreferredSize();
                director.setBounds(100, 150 ,
                         size.width, size.height);
                 size = director2.getPreferredSize();
                director2.setBounds(200 , 150 ,
                         size.width, size.height);
                size = genre.getPreferredSize();
                genre.setBounds(100 , 200 ,
                         size.width, size.height);
                 size = genre2.getPreferredSize();
                genre2.setBounds(200 , 200 ,
                         size.width, size.height);
                 size = year.getPreferredSize();
                year.setBounds(100 , 250 ,
                         size.width, size.height);
                size = year2.getPreferredSize();
                year2.setBounds(200 , 250 ,
                         size.width, size.height);
                 size = plot.getPreferredSize();
                plot.setBounds(100 , 300 ,
                         size.width, size.height);
                 size = plot2.getPreferredSize();
                plot2.setBounds(200 , 300 ,
                         size.width, size.height);
                size = rating.getPreferredSize();
                rating.setBounds(100 , 350 ,
                         size.width, size.height);
                 size = rating2.getPreferredSize();
                rating2.setBounds(200 , 350 ,
                         size.width, size.height);
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            frame.add(new real2());
            //Display the window.
            frame.setSize(600, 360);
            frame.setVisible(true);
            frame.pack();
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        public void actionPerformed(ActionEvent e) {
            if ("Add New".equals(e.getActionCommand())){
               frame1 = new JFrame("add");
               frame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
               addComponentsToPane(frame1.getContentPane());
               frame1.setSize(600, 500);
               frame1.setVisible(true);
                //disableing first frame etc:-
                if (frame1.isShowing()){
                addnew.setEnabled(false);
                help.setEnabled(false);
                exit.setEnabled(true);
                frame1.setVisible(true);
               }else{
                addnew.setEnabled(true);
                help.setEnabled(true);
                exit.setEnabled(true);           
            if ("Exit".equals(e.getActionCommand())){
                System.exit(0);
            if ("Save".equals(e.getActionCommand())){
                // whatever i ask it to do it wont for example---
                help.setEnabled(true);
            if ("Save" == e.getSource()) {
                //i tried this way too but it dint work here either
                help.setEnabled(true);
    }so if someone could help me by either telling me what to type or by replacing what iv done wrong that would be great thanks...

    (1)Java class name should begin with a capital letter. See: http://java.sun.com/docs/codeconv/
            JButton save = new JButton("Save");
            JButton save2 = new JButton("Save and add another");
            // ... etc. ...(2)Don't redeclare class members in a method as its local variable. Your class members become eternally null, a hellish null.
    how to make them work when clicked on(3)Add action listener to them.

  • The keyboard and trackpad on MacBook Air (13-inch, Mid 2013) computers may stop functioning at the Personalize step when installing Windows 7 64bit

    The keyboard and trackpad on MacBook Air (13-inch, Mid 2013) computers may stop functioning at the Personalize step when installing Windows 7 64bit.

    1. Reset PRAM.  http://support.apple.com/kb/PH4405
    2. Reset SMC.     http://support.apple.com/kb/HT3964
        Choose the method for:
        "Resetting SMC on portables with a battery you should not remove on your own".
    If this does not help, contact Apple.

  • Getting values from JLabel[] with JButton[] help!

    Hello everyone!
    My problem is:
    I have created JPanel, i have an array of JButtons and array of JLabels, they are all placed on JPanel depending from record count in *.mdb table - JLabels have its own value selected from Access table.mdb! I need- each time i press some button,say 3rd button i get value showing from 3rd JLabel in some elsewere created textfield, if i have some 60 records and 60 buttons and 60 labels its very annoying to add for each button actionlistener and for each button ask for example jButton[1].addActionListener() ...{ jLabel[1].getText()......} and so on!
    Any suggestion will be appreciated! Thank you!

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing
      public void buildGUI()
        final int ROWS = 10;
        JPanel[] rows = new JPanel[ROWS];
        final JLabel[] labels = new JLabel[ROWS];
        JButton[] buttons = new JButton[ROWS];
        JPanel p = new JPanel(new GridLayout(ROWS,1));
        final JTextField tf = new JTextField(10);
        ActionListener listener = new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            tf.setText(labels[Integer.parseInt(((JButton)ae.getSource()).getName())].getText());
        for(int x = 0; x < ROWS; x++)
          labels[x] = new JLabel(""+(int)(Math.random()*10000));
          buttons[x] = new JButton("Button "+x);
          buttons[x].setName(""+x);
          buttons[x].addActionListener(listener);
          rows[x] = new JPanel(new GridLayout(1,2));
          rows[x].add(labels[x]);
          rows[x].add(buttons[x]);
          p.add(rows[x]);
        JFrame f = new JFrame();
        f.getContentPane().add(p,BorderLayout.CENTER);
        f.getContentPane().add(tf,BorderLayout.SOUTH);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }

  • You do not have permission to access service Personalization

    This is certainly new to me. I am attempting to directly access a MII Application web page by URL in MII V 12.1 and get this message when using my basic user login:
    You do not have permission to access service Personalization
    It works fine with my admin login. I have dug around in Netweaver and MII and can't find where I turn this on. What is the magic bullet? Is there a particular role or group the basic user must be a member of?
    Thanks in advance for your help.
    ...Sparks

    Make sure you belong to SAP_XMII_Users
    http://help.sap.com/saphelp_mii121/helpdata/en/45/5a399bec592a4de10000000a11466f/content.htm
    http://help.sap.com/saphelp_mii121/helpdata/en/48/d0c6efbcb810b6e10000000a421138/content.htm
    This is a change to security and permissioning in 12.1 where UME Actions are used.

  • Problem with KeyAdapter and JButtons in a Jframe

    yes hi
    i have searched almost most of the threads here but nothing
    am trying to make my frame accepts keypress and also have some button on the frame here is the code and thank you for the all the help
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class RPg extends JFrame implements ActionListener
                private int width;
                private int hight;
                public    JPanel north;
                public    JPanel se;
                public    JButton start;
                public    JButton quit;
                public    Screen s;//a Jpanel
                public    KeyStrokeHandler x;
        public RPg() {
               init();
               setTitle("RPG");
               setSize(width,hight);
               setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               setResizable(false);
               setVisible(true);
               x=new KeyStrokeHandler();
             addKeyListener(x);
             public void init() {
               north=new JPanel();
               Container cp = getContentPane();
               s=new Screen();
               this.width=s.width;
               this.hight=s.hight+60;
              start=new JButton("START");
                  start.addActionListener(this);
              quit=new JButton("QUIT");
                  quit.addActionListener(this);
              north.setBackground(Color.DARK_GRAY);
              north.setLayout(new FlowLayout());
              north.add(start);
              north.add(quit);
              cp.add(north, BorderLayout.NORTH);
              cp.add(s, BorderLayout.CENTER);
        public static void main(String[] args) {
            RPg rpg = new RPg();
       public void actionPerformed(ActionEvent ae) {
            if (ae.getActionCommand().equals("QUIT")) {
                     System.exit(0);
            if (ae.getActionCommand().equals("START")) { }
       class KeyStrokeHandler extends KeyAdapter {
               public void keyTyped(KeyEvent ke) {}
               public void keyPressed(KeyEvent ke){
                  int keyCode = ke.getKeyCode();
                  if ((keyCode == KeyEvent.VK_M)){
                     System.out.println("it works");
               public void keyReleased(KeyEvent ke){}

    Use the 'tab' key to navigate through 'contentPane > start > quit' focus cycle. 'M' key works when focus is on contentPane (which it is on first showing). See tutorial pages on 'Using Key Bindings' and 'Focus Subsystem' for more.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class RPG extends JFrame implements ActionListener {
        private int width;
        private int hight;
        public JPanel north;
        public JPanel se;
        public JButton start;
        public JButton quit;
        public Screen s;    //a Jpanel
        public RPG() {
            init();
            setTitle("RPG");
            setSize(width,hight);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setResizable(false);
            setVisible(true);
        public void init() {
            north=new JPanel();
            Container cp = getContentPane();
            registerKeys((JComponent)cp);
            s=new Screen();
            this.width=s.width;
            this.hight=s.hight+60;
            start=new JButton("START");
                start.addActionListener(this);
            quit=new JButton("QUIT");
                quit.addActionListener(this);
            north.setBackground(Color.DARK_GRAY);
            north.setLayout(new FlowLayout());
            north.add(start);
            north.add(quit);
            cp.add(north, BorderLayout.NORTH);
            cp.add(s, BorderLayout.CENTER);
        public static void main(String[] args) {
            RPG rpg = new RPG();
        public void actionPerformed(ActionEvent ae) {
            if (ae.getActionCommand().equals("QUIT")) {
                     System.exit(0);
            if (ae.getActionCommand().equals("START")) { }
        private void registerKeys(JComponent jc)
            jc.getInputMap().put(KeyStroke.getKeyStroke("M"), "M");
            jc.getActionMap().put("M", mAction);
        Action mAction = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("it works");
    class Screen extends JPanel {
        int width, hight;
        public Screen() {
            width = 300;
            hight = 300;
            setBackground(Color.pink);
    }

Maybe you are looking for