JButton rollover paints itself over stacked layers

Hi all,
I have a UI with two stacked layers. The bottom layer has a number of buttons with roll-over images, and the upper panel is a semi-opaque JPanel.
When a button is rolled over, the roll-over image paints itself on top of the semi-opaque top layer. Likewise, if any button is clicked (roll-over image or no roll-over image), the button paints itself on top.
I've tried adding in lots of repaint methods so that when the button is clicked the top layer will repaint, and while that helps it still causes flickering. Preferably, the buttons should realize they're on the bottom layer and shouldn't be painting on top.
A simple self-contained example is below (without the extra repaint() methods).
Anyone have any ideas on this? Any help much appreciated!
Sam
import java.awt.*;
import javax.swing.*;
public class LayerTester {
     private static JComponent createTesterPanel(){
          JPanel lowerPanel = new JPanel(new BorderLayout());
          JButton button1 = new JButton("Button 1");
          lowerPanel.add(button1, BorderLayout.NORTH);
          JButton button2 = new JButton("Button 2");
          lowerPanel.add(button2, BorderLayout.CENTER);
          JButton button3 = new JButton("Button 3");
          lowerPanel.add(button3, BorderLayout.SOUTH);
          * This adds a roll-over listener (A real program would set
          * a more interesting icon). Because of this, mousing
          * over the button causes the button to be painted over
          * the dimmerPanel
          button2.setRolloverIcon(button1.getDisabledIcon());
          JPanel dimmer = new DimmerPanel();
          JPanel stack = new JPanel();
          stack.setLayout(new OverlayLayout(stack));
          stack.add(dimmer);
          stack.add(lowerPanel);
          return stack;
  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(createTesterPanel());
    f.setPreferredSize(new Dimension(200,200));
    f.pack();
    f.setVisible(true);
  private static  class DimmerPanel extends JPanel
       public DimmerPanel(){
            setOpaque(false);
       protected void paintComponent(Graphics g) {
             super.paintComponent(g);
             Graphics2D g2 = (Graphics2D)g;
             AlphaComposite ac =
                 AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
             g2.setComposite(ac);
             g2.fillRect(0, 0, getWidth(), getHeight());
             g2.dispose();
}

Heres one way using layered panes:
import java.awt.*;
import javax.swing.*;
public class LayerTester {
     private static JComponent createTesterPanel(){
          JPanel lowerPanel = new JPanel(new BorderLayout());
          JButton button1 = new JButton("Button 1");
          lowerPanel.add(button1, BorderLayout.NORTH);
          JButton button2 = new JButton("Button 2");
          lowerPanel.add(button2, BorderLayout.CENTER);
          JButton button3 = new JButton("Button 3");
          lowerPanel.add(button3, BorderLayout.SOUTH);
          lowerPanel.setPreferredSize( new Dimension(200, 200) );
          lowerPanel.setSize(lowerPanel.getPreferredSize());
          * This adds a roll-over listener (A real program would set
          * a more interesting icon). Because of this, mousing
          * over the button causes the button to be painted over
          * the dimmerPanel
          button2.setRolloverIcon(button1.getDisabledIcon());
          JPanel dimmer = new DimmerPanel();
          dimmer.setSize(100, 100);
//          JPanel stack = new JPanel();
//          stack.setLayout(new OverlayLayout(stack));
          JLayeredPane stack = new JLayeredPane();
          stack.setPreferredSize( lowerPanel.getPreferredSize() );
          stack.add(lowerPanel, new Integer(1));
          stack.add(dimmer, new Integer(2));
          return stack;
  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(createTesterPanel());
//    f.setPreferredSize(new Dimension(200,200));
    f.pack();
    f.setVisible(true);
  private static  class DimmerPanel extends JPanel
       public DimmerPanel(){
            setOpaque(false);
       protected void paintComponent(Graphics g) {
             super.paintComponent(g);
             Graphics2D g2 = (Graphics2D)g;
             AlphaComposite ac =
                 AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
             g2.setComposite(ac);
             g2.fillRect(0, 0, getWidth(), getHeight());
             g2.dispose();
}

Similar Messages

  • I have a new Samsung phone and I live in CT. Last month they charged me $38 on my bill for the sales tax for the new phone which was $600. I'm paying for the phone itself over 20 installments of $30 each.  Now again I'm getting that same $38 charge. I can

    I have a new Samsung phone and I live in CT. Last month they charged me $38 on my bill for the sales tax for the new phone which was $600. I'm paying for the phone itself over 20 installments of $30 each.  Now again I'm getting that same $38 charge. I can't  believe that the monthly CT tax is higher than the payment for the phone itself. Does this make sense. Last time I spoke with them on the phone it was for 1 1/4 hours for something simple. I don't want to call unless I need to. The salesman told me nothing about any of this. Thank you for any help you can offer.

    The bill from last month states:
    CT state sales tax**     $38.10
    ** In some states sales tax or surcharges are calculated on the full cost of the full retail price or VZW cost of the device you purchased and not on the discounted price you pay. The sales tax or surcharges charged on your device was based on $599.99 and appears on this first bill.
    The current bill says the same.
    Actually, now I'm realizing that last month's bill stated I was making the first payment toward the phone. Now this month also says it's the first payment toward the phone when it's really the second.

  • Attempted to reboot - but refuses to boot up all the way.  It keeps rebooting itself over and over.  I've also tried to restore it to no avail.  Help!

    Attempted to reboot - but refuses to boot up all the way.  It keeps rebooting itself over and over.  I've also tried to restore it to no avail.  Help!

    Try restoring the iPhone from recovery mode.
    If that doesn't do it, the iPhone will beed to be sent back to Apple for repair, head on over to the Service Answer Center for the iPhone.

  • How to create objects to paint itselfs without specifiy the location

    How to create objects to paint itselfs without specifiy the location using Java 2D

    shot in the dark: pass in the Graphics2D context to the method ?

  • KDL-43W800C BRAVIA Android TV Restarts itself over and over

    KDL-43W800C BRAVIA Android TV Restarts itself over and over.TV purchased on 30/6/2015 from PAI International Bangalore getting restarted automatically hightly disappointing ,considering Sony Brand value i purchased this costly LED .Sony Service request # 26296866.Sony chat representative asked me to do factory reset which didnt yield any result.Sony design & Manufacturing team could you please google with search word "Sony Bravia restart itself" & you will find multiple posts like below ;
    https://www.community.sony.com/t5/Television-General/KDL-52V5100-BRAVIA-Restarts-itself-over-and-over/td-p/130867It is proved to be a Known issue with Sony Bravia TV's & Sony seems to be not serious to fix this issue but selling the defective / Problematic products to customers who gets fooled after paying high price just for the Brand value. My question here is IF SONY DOING PRODUCT TESTING IN CUSTOMER PLACE ? , Do you have Known error database , Root cause analysis , Problem fixing approach atall ?.Did i do a mistake by selecting your product ? if this issue isnt fixed i want you to take back the set & refund the entire amount. Please Dont sell any product till its completly tested & verified from now on..

    Yes Restart issue got fixed Sony Service request # 26296866 : technical person visited my place & installed the latest software which seems to have fixed & i have been monitoring it from last 2 weeks.---------------------------------------------------------------------------------------------------------------------------Along with the above issue i reported "Ghosting on LED screen / White patches all over screen " when on & no signal input mode ,when my set top box is powered off.
    My issue is exactly mentioned as "Mura Effect type 1 " in below link : http://sonyclouding.blogspot.in/2007/01/what-is-mura.html
    "Mura Effect type 1 corresponds to a lack of homogeneity in control circuit adjustments. From one cell to another color control can change and it will lead to permanent defects in intensity in displayed images.engineer who visited my place to fix the reboot issue said Mura ghosting issue is common on Majority of Sony TV & its not an issue to worry about as the patches are not visible when the tv is on Tatasky mode when pictures are displayed. I should not worry abt this is no signal / black screen mode.I have writtent to Sony as below & awaiting response :1. Do you also agree that Mura effect as a known issue & customers like me need not to worry if so ? Sony are you ready to give my tv the lifetime warranty for the LED screen, if this Mura affect leads to serious damage to my screen after my warranty period i may have to invest 20 to 30k INR to get a replacement screen.2. https://community.sony.com/t5/Television-General/KDL-43W800C-BRAVIA-Android-TV-Restarts-itself-over-and-over/m-p/512249Mura effect issue raised by user of Sony community portal "Steve1570z" dead/stuck pixel on the lower right part of the screen. It was refunded, though - So Sony has accepted this issue & indeed refunded the purchase amount to the consumer.If Sony India can follow the same process or this varies b/w country to country ?

  • Is there an option to have the cursor automatically position itself over the preferred default on an option screen (like when given the options to select OK or CANCEL). I believe this feature existed on 3.6. THANKS!

    In v4 RC the cursor just sits on the lower left of screen, doesn't position itself on the recommended option when the select-option screen comes up. On previous versions of FF the cursor positioned itself over the recommended option.

    Hi blabla12345,
    (untested and without warranty)
    replace this line:
    const sSaveCUBE = "CUBE";
    with this:
    const sSaveCUBE = "cube";
    Have fun

  • Was installing osx mavericks and now the iMac is restarting itself over and over

    Was installing osx mavericks and now the iMac is restarting itself over and over

    Shut the power clear off, wait a minute or 2 and restart and see if that clears the problem.
    Don

  • My Defined brush duplicates itself over and over when applied to any image!!!??

    Hi there, I recently loaded in my signature for my photography and each time I click the signature to apply it to an image it appears fine, however when it is applied to the image it is replicated about 6 times in a pattern effect!
    Any suggestions?

    Thanks so much! I figured it out!
    Date: Wed, 24 Nov 2010 20:16:19 -0700
    From: [email protected]
    To: [email protected]
    Subject: My Defined brush duplicates itself over and over when applied to any image!!!??
    Make sure the airbrush is off and check the other settings as indicated below.
    http://forums.adobe.com/servlet/JiveServlet/showImage/49162/pse-brush.png
    MTSTUNER
    >

  • Adjustment Layers-- painting back over not working

    I'm learning adjustment layers. When I try to reverse what I've painted out by inverting the brush color and painting, nothing happens, i.e. the original brushwork stays intact and doesn't reverse. There is no lock icon on the layer. What am I doing wrong? Thanks.

    Sounds like you are working on the mask. Make sure your foreground and background colors are black and white (literally).
    Make sure the correct layer is selected
    Make sure the mask thumbnail is selected.
    Make sure the brush settings are correct in the top toolbar, - normal blend mode, 100% opacity
    Make sure the layers settings are correct - check blend mode and opacity
    make sure no layer above that layer is affecting it.
    If none of this works, capture your screen with the layers panel open and post it.

  • How can I stack layers in the layers column?  Each layer is appearing only by itself.

    Have spent the last four hours trying all sorts of combos to have my layers stack in the layers column.  They only appear one at a time as I click on their icons in the bin at the bottom of the page.  I am quite familiar with Photoshop where this was never a problem,but recently purchased Elements for my new computer so that I could design several self-published bookcovers.  I need the layers so that I can work with cover guides.  The 'help' tutorials and Elements for Dummies have been of no use on this issue.
    Suggestions, please -- I really need help. Thanks!

    Sorry, I don't understand your question completely.
    The project bin, which is at the bottom below the work space, is populated by picture files that are being processed.
    The layer palette reflects the individual layers that have been generated in reference to a picture that is being enhanced/modified.
    If you want a stamp visible or composite layer embracing all of the layers, yet don't want to flatten, open a blank new layer at the top of the stack, then press
    CTRL+SHIFT+ ALT+E.

  • Painting and using different Layers

    Hi,
    I have to develop a Swing interface where i have to do lot of painting,
    Like there will be a background which will be showing some strips with different colors, which will be stable,
    On this background I have to draw some rectangle , off different size,
    and add the function so the user can click on the rectangle and drag it and drop it
    I have to develop a kind of scheduling , like microsoft scheduler or take a look at the following example
    http://www.ilog.com/products/jviews/demos/activitychart/index.cfm
    I need some help in finding some tutorial on how to use different panes in JApplet , like th layered panes, the glass panes etc
    Any advice on developing such an Applet
    Ashish

    Hi Shannon,
    I already have subclassed JPanel and override the paintComponent method to do all the painting , but the problem i am having is there is a lot of painting and when ever i move the mouse over it repaint method is called and so there is chance that the applet will not work if the graphics card of the user is not good,
    Can u point me to some example where a RepaintManager() is used,
    also i want to use layers so i can avoid the repainting of the background even if the user clicks on it, or drap and drops the rectangle drawn
    Ashish

  • FAQ: How do I make a hand cursor display on rollover or mouse over?

    You can make a component in your application, for example a button or custom component, display a pointing finger cursor when a user's mouse rolls over it. Select the component, and in the Appearance section of the Properties panel, check Hand cursor.
    Read the quick tip on FlashCats.

    Hi there
    Another approach is to use a Rollover Caption. Just remove any text and configure the caption as transparent. Then layer the Rollover area over the part where you want the hand to change to a cursor. The net effect will be that the cursor change will occur. Clicking will then result in triggering the underlying Submit button, which appers to be invisible and layered over an image.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Help to Make Stacked Layers Expand with Copy

    I have multiple layers stacked on an html page. I need the
    third layer, which holds text, to force the layers beneath it to
    expand when the copy exceeds the initial size of the layer.
    I tried using the nested layer function, but either I am
    doing something wrong or this is not the proper way to make this
    happen. The original layer (gray) shows sublayers beneath it (in
    the Layers window) but the parent is not expanding to accomodate
    the sublayer expansion.
    I am trying to create a template and need that text area to
    be able to expand as needed, without overlapping the layers beneath
    it. Help?

    It cannot happen. This is one of the downsides to using
    'layers'. Since
    they are removed from the normal flow (by virtue of being
    absolutely
    positioned), then cannot then affect any other element's size
    or position.
    In fact, this downside is SO severe that using layers as a
    general layout
    method is a very poor practice. See this for alternative
    approaches -
    http://apptools.com/examples/pagelayout101.php
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "BabyOz" <[email protected]> wrote in
    message
    news:f9smg1$p6r$[email protected]..
    >I have multiple layers stacked on an html page. I need
    the third layer,
    >which
    > holds text, to force the layers beneath it to expand
    when the copy exceeds
    > the
    > initial size of the layer.
    >
    > I tried using the nested layer function, but either I am
    doing something
    > wrong
    > or this is not the proper way to make this happen. The
    original layer
    > (gray)
    > shows sublayers beneath it (in the Layers window) but
    the parent is not
    > expanding to accomodate the sublayer expansion.
    >
    > I am trying to create a template and need that text area
    to be able to
    > expand
    > as needed, without overlapping the layers beneath it.
    Help?
    >
    >
    >

  • Question-Super Imposing Line over stacked

    Hi
      I have used a line chart over an stacked chart and i have used the secondary axis for the line chart. The idea of doing so is that the line chart controls my sales data and the stacked chart shows me the spend on different sectors. both the charts are controlled by a combo box for months. When i try to change the months the charts behave in a haphazard way with the axis moving over one another. how do i resolve such an issue ?

    Hi
    You'll need to synchronise both of the chart's scales, to manual and probably have a formulae to work out when the best Min and Max values should be for both charts.
    Thanks
    Charles

  • Clipping Mask over Multiple Layers

    Hi,
    I have a multiple layer file and I want to apply a clipping mask over the entire design as my last step to block out all of the excess around the edges of the clipboard. Every time I try this the layers are merged into one but I want to maintain the layers.
    Is it possible to have a mask and keep the layers?

    Make a new layer and drag all the existing layers into in, making them sublayers. Draw your mask in this master layer, select it, and go to Make Clipping Mask in the Layers panelette.

Maybe you are looking for

  • Problem with Flash Player in IE7 / IE8

    I'm stumped. I've got a problem running Flash content in IE7 / IE8. I had Adobe Master Suite CS3 installed on my laptop, and had no issues running Flash content in any browser including IE7 when this was installed. I've recently un-installed it and c

  • Intercompany Stock transfer order with excise

    Hi, Can anyone  tell me about Intercompany Stock transfer order with excise step by step. hoping to replu

  • Files not showing up in shared folder

    I am in a network environment (8 G5 imacs and a G4 Power Mac Server) The G5's are running OSX 10.3.9 and the G4 Sever is running Max OSX Sever10.3. Two of the G5 imacs need to unmount the shared folder and remount to see new content placed in the fol

  • Can't get proc to work on RH7

    Hi. I have created a very simple program called test.pc which works OK on the AIX box. But I got the following error message from the RH7 machine: extern int fchown (int __fd, __uid_t __owner, __gid_t __group) __THROW; ...............................

  • Why does Safari keep saying "it can't connect to the server" every time I try to access any sites?

    I have the latest safari update for os x, which was working perfectly fine up until 3 days ago. Everytime I would try to access any site, safari would tell me it couldn't connect to the server, and I would have to refresh the page at least 5-10 times