JPanel Transparency Causes Artifacts

I am working on a battleship game an have a JPanel class which has a transparent color for a background (setBackground(new Color(1f, 1f, 1f, .25f));). When the panel is repainted, lots of artifacts appear and the background is one-half as transparent. Also, the current text is repainted on top of the previous text. I have searched the bug database and found that this is a common issue and can be worked around using setOpaque(false) and overriding paintComponent to paint the background. I did this, but there are still a significant amount of artifacts on the panel. Any ideas? Has anyone else seen this issue before? If so, how did you solve it?
Conditions:
J2SDK1.5.0 Beta1
Windows XP Pro (2 Different Machines)
Here's my paintComponent code:
public void paintComponent(Graphics g)
     g.setColor(new Color(1f, 1f, 1f, .25f));
     g.fillRect(0, 0, getWidth(), getHeight());
     super.paintComponent(g);
}Thanks
Blake
[email protected]

The artifacts are not caused by paintComponent. I posted it for reference to my second question. Maybe I should have seperated the questions for more clarity.
1. How do I work around the artifact issue?
2. I've read of a custom background painting workaround. Has anyone else heard of it? Did the paintComponent method body I posted in the initial post correctly address this issue?
To answer your question, I initialize no explicit Threads of any kind. I tried, but it made the artifacts worse.
Thanks.
Blake
[email protected]

Similar Messages

  • How to make a JPanel transparent? Not able to do it with setOpaque(false)

    Hi all,
    I am writing a code to play a video and then draw some lines on the video. For that first I am playing the video on a visual component and I am trying to overlap a JPanel for drawing the lines. I am able to overlap the JPanel but I am not able to make it transparent. So I am able to draw lines but not able to see the video. So, I want to make the JPanel transparent so that I can see the video also... I am posting my code below
    import javax.media.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import java.lang.Math;
    import javax.media.control.FramePositioningControl;
    import javax.media.protocol.*;
    import javax.swing.*;
    class MPEGPlayer2 extends JFrame implements ActionListener,ControllerListener,ItemListener
         Player player;
         Component vc, cc;
         boolean first = true, loop = false;
         String currentDirectory;
         int mediatime;
         BufferedWriter out;
         FileWriter fos;
         String filename = "";
         Object waitSync = new Object();
         boolean stateTransitionOK = true;
         JButton bn = new JButton("DrawLine");
         MPEGPlayer2 (String title)
              super (title);
              addWindowListener(new WindowAdapter ()
                   public void windowClosing (WindowEvent e)
                            dispose ();
                            public void windowClosed (WindowEvent e)
                         if (player != null)
                         player.close ();
                         System.exit (0);
              Menu m = new Menu ("File");
              MenuItem mi = new MenuItem ("Open...");
              mi.addActionListener (this);
              m.add (mi);
              m.addSeparator ();
              CheckboxMenuItem cbmi = new CheckboxMenuItem ("Loop", false);
              cbmi.addItemListener (this);
              m.add (cbmi);
              m.addSeparator ();
              mi = new MenuItem ("Exit");
              mi.addActionListener (this);
              m.add (mi);
              MenuBar mb = new MenuBar ();
              mb.add (m);
              setMenuBar (mb);
              setSize (500, 500);
              setVisible (true);
         public void actionPerformed (ActionEvent ae)
                        FileDialog fd = new FileDialog (this, "Open File",FileDialog.LOAD);
                        fd.setDirectory (currentDirectory);
                        fd.show ();
                        if (fd.getFile () == null)
                        return;
                        currentDirectory = fd.getDirectory ();
                        try
                             player = Manager.createPlayer (new MediaLocator("file:" +fd.getDirectory () +fd.getFile ()));
                             filename = fd.getFile();
                        catch (Exception exe)
                             System.out.println(exe);
                        if (player == null)
                             System.out.println ("Trouble creating a player.");
                             return;
                        setTitle (fd.getFile ());
                        player.addControllerListener (this);
                        player.prefetch ();
         }// end of action performed
         public void controllerUpdate (ControllerEvent e)
              if (e instanceof EndOfMediaEvent)
                   if (loop)
                        player.setMediaTime (new Time (0));
                        player.start ();
                   return;
              if (e instanceof PrefetchCompleteEvent)
                   player.start ();
                   return;
              if (e instanceof RealizeCompleteEvent)
                   vc = player.getVisualComponent ();
                   if (vc != null)
                        add (vc);
                   cc = player.getControlPanelComponent ();
                   if (cc != null)
                        add (cc, BorderLayout.SOUTH);
                   add(new MyPanel());
                   pack ();
         public void itemStateChanged(ItemEvent ee)
         public static void main (String [] args)
              MPEGPlayer2 mp = new MPEGPlayer2 ("Media Player 2.0");
              System.out.println("111111");
    class MyPanel extends JPanel
         int i=0,j;
         public int xc[]= new int[100];
         public int yc[]= new int[100];
         int a,b,c,d;
         public MyPanel()
              setOpaque(false);
              setBorder(BorderFactory.createLineBorder(Color.black));
              JButton bn = new JButton("DrawLine");
              this.add(bn);
              bn.addActionListener(actionListener);
              setBackground(Color.CYAN);
              addMouseListener(new MouseAdapter()
                             public void mouseClicked(MouseEvent e)
                   saveCoordinates(e.getX(),e.getY());
         ActionListener actionListener = new ActionListener()
              public void actionPerformed(ActionEvent aae)
                        repaint();
         public void saveCoordinates(int x, int y)
                    System.out.println("x-coordinate="+x);
                    System.out.println("y-coordinate="+y);
                    xc=x;
              yc[i]=y;
              System.out.println("i="+i);
              i=i+1;
         public Dimension getPreferredSize()
    return new Dimension(500,500);
         public void paintComponent(Graphics g)
    super.paintComponent(g);
              Graphics2D g2D = (Graphics2D)g;
              //g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
              g2D.setColor(Color.GREEN);
              for (j=0;j<i;j=j+2)
                   g2D.drawLine(xc[j],yc[j],xc[j+1],yc[j+1]);

    camickr wrote:
    "How to Use Layered Panes"
    http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html
    Add your video component to one layer and your non-opaque panel to another layer.Did you try that with JMF? It does not work for me. As I said, the movie seems to draw itself always on top!

  • Making a JPanel transparent

    In the application I am writing I want to allow for some popups on my interface. I am using a JLayeredPane, with two JPanels. The main JPanel, on the default layer, holds all the main components. A second JPanel, at the popup layer, will hold any components which should "pop up".
    The layered pane is using a border layout, with both JPanels in the Center.
    Unfortunately the bottom panel cannot be seen. It is covered by the top panel, even after I called setOpague(false) on the top panel.
    Am I taking the wrong approach? Or is it just not possible to make a JPanel transparent?

    It should work.I have fiddled around, but have been unable to get this to work. It seems obvious that I'm doing something wrong. :( Below is an example which mimicks my real code, and hopefully is simple enough.
    I appreciate any help you can provide.
    import java.awt.BorderLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JLayeredPane;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    public class MyPanel extends JPanel
         public MyPanel()
              setLayout(new BorderLayout());
              add(createLayeredPane(), BorderLayout.CENTER);
         private JLayeredPane createLayeredPane()
              JPanel mainPanel = createMainPanel();
              JPanel popupPanel = createPopupPanel();
              JLayeredPane pane = new JLayeredPane();
              pane.setLayout(new BorderLayout());
              pane.add(mainPanel, BorderLayout.CENTER);
              pane.add(popupPanel, BorderLayout.CENTER);
              pane.setLayer(mainPanel, JLayeredPane.DEFAULT_LAYER.intValue());
              pane.setLayer(popupPanel, JLayeredPane.POPUP_LAYER.intValue());
              return pane;
         private JPanel createMainPanel()
              JList list = new JList(new Object[]{"One","Two","Three"});
              JButton button = new JButton("Do Nothing");
              JPanel panel = new JPanel();
              panel.setLayout(new BorderLayout());
              panel.add(new JScrollPane(list), BorderLayout.CENTER);
              panel.add(button, BorderLayout.SOUTH);
              return panel;
         private JPanel createPopupPanel()
              JLabel label = new JLabel("Hello world!");
              label.setOpaque(false);
              JPanel panel = new JPanel();
              panel.setOpaque(false);
              panel.add(label);
              return panel;
         public static void main(String[] args)
              MyPanel panel = new MyPanel();
              JFrame mainFrame = new JFrame("Testing");
              mainFrame.setContentPane(panel);
              mainFrame.pack();
              mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              mainFrame.show();
    }

  • Spot colors and Transparency causing Overprint knock-out

    Whenever I create a PDF from InDesign (CS3) I get missing artefacts/items on print production.
    It is caused by a transparent PSD file being laid over a spot color.
    I print a /ps file and then Distill to Press Quality.
    Overprint preview in ACrobat Pro shows what I need by overprint off I lose info - this causes immense problems at all the pre-pre studios I use.
    Any pointers to a cure/reason?
    (more info if needed upon request)

    For one, please do not go through PostScript , rather export to PDF directly. When doing so, you may want to do the transparency flattening either during PDF export (i.e. in Indesign) or later on in Adobe Acrobat Pro.
    Going through PostScript/distilling adds extra potential for issues.
    Next, any print service provider who is not in a position to deal reliably with overprints, does not deserve a contract from a high profile client. Rather, find print service providers who are up to the task. A decent print service provider should produce a result that is visually very very close to what you see in Adobe Acrobat Pro having turned on Overprint Simulation and Output Preview. If the output from a print service provider suffers from missing portions or other artifacts (as those that can be seen when Overprint simulation and Overprint Preview are turned off in Acrobat Pro) then that print service provider is simply failing.
    Finally - as pointed out by Jon, the best approach is to keep the transparency in your PDFs alive and find print service providers that can deal with it (because for example they have a workflow based on the Adobe PDF Print Engine).
    Olaf Druemmer
    PS: ... or would you accept a week old bread rolls from your baker?

  • WMODE="transparent" causes pop-up blocking

    Ok, I know this sounds strange... I have 2 versions of the
    same page, one with WMODE=”transparent” and the other
    without.
    With:
    http://www.cabovillas.com/maps.asp
    Without:
    http://www.cabovillas.com/maps_pop.asp
    The menu dropdown appears above the map on the page WITH the
    transparency, as it should, but the pop-ups are blocked by IE
    (click on the US map then click on Cabo San Lucas - the pop-up is
    blocked.)
    On the page WITHOUT transparency, the drop-down menu appears
    behind the map, as expected - but unwanted, and IE doesn't block
    the pop-ups.
    So, I can have the drop-down appear above the map and block
    the pop-ups, or have the dropdown appear under the map, with no
    blockage. Does this make sense? Any way to have the drop-down
    appear above the map, and not block the pop-ups?
    Thanks!

    Doesn't sound strange at all. Have you searched these forums
    for WMODE?
    It causes all kinds of crazy problems. Generally not
    universally reproducible and totally dependent upon EXACTLY which
    version of plugin, browser, phase of the moon, and platform.
    Sorry I don't have any answer because I've never needed to do
    what you are trying to do. Search the forums and see what has been
    suggested.

  • Advice for JPanel transparency idea

    Hi!
    I've spent all day reading about the CardLayout and JLayeredPane and am confused as to which route to take.
    Here's what I'm planning to build:
    - One frame containing three panels.
    - Each panel holds an invididual image and and stretches to the extents of the frame, thus the panels sit on top of each other.
    - I would like to be able to change the order of the panels
    - Here's the killer: I'd like to change the transparancy of the top panel (either partially or completely) so that I can peer through to the panel below.
    Any advice would be appreciated. Many thanks...

    To summarise (thanks J_Rooze for advice):
    - Setting the AlphaComposite value before calling super.paintComponent(g2) will change the transparency of the whole panel.
    - Performance will drop in the order of ~40%, but using J_Rooze's suggestion to force the OpenGL rendering pipeline (above) completely remedies this (is there a similar hack for java3D?? :-).
    - Using these panels with JLayeredPane worked completely for my spec (top post).
    - I also tried them in CardLayout, however, whilst I could get the top panel to go transparent the underneath panel would not show through. This might not necessarily be a problem for other specs.
    - Panels should be .setOpaque(false) to eliminate crazy phasing effects.
    Here's my working code for reference:
    import java.awt.*;
    import javax.swing.JPanel;
    public class DisplayPanel extends JPanel{
         private boolean antiAlias;
         private float alpha = 1.0f;
         public DisplayPanel(boolean setAntiAlias) {
              antiAlias = setAntiAlias;
              this.setOpaque(false);
         public void setAlpha(float a) {
              alpha = a;
              if (alpha > 1) alpha = 1.0f;
              if (alpha < 0) alpha = 0.0f;
              repaint();
         public float getAlpha() {
              return alpha;
         protected void paintComponent(Graphics g) {
              Graphics2D g2 = (Graphics2D)g;
              AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha());
              g2.setComposite(ac);
              super.paintComponent(g2);
              // for speed
              g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
              g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
              if (antiAlias) g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              //draw commands go here
    }Edited by: .eD on May 7, 2008 4:46 AM

  • Making JPanels transparent changes the look of the frame

    Hi,
    I wanted to set a background image on my internal frame, which contains more edits and buttons. This was easy, I set the image as background on the frame panel, then made all the JPanels containing elements transparent (=opaque(false)) so that the background is now visible.
    Now my problem is that when there is no image to load (or no background wished) the former look of my frame became strage: there are 2 nouances of grey, the old gray from buttons is still there, but the containing panels are in a darker gray then the before. It seems to hang together with the new transparent panels. Setting a background color doesn't seem to help too...Do you have any idea, how could I restore the old "same gray overall" look?
    Thanks for helping,
    maria

    You may find the answer at the link shown below:
    http://java.sun.com/products/jfc/tsc/articles/swing2d/index.html
    Without seeing any code, I am guessing that the container's background is showing thru the first transparent component and the next's component's background is being added on top of it.
    ;o)
    V.V.

  • Images with Transparency Cause Rendering Bug in Acrobat

    Try this at home: Export a file containing an image with transparency to PDF and open it in Acrobat (any platform, any recent version): the page containing the image will have all text rendered in what looks like bold or faux bold, depending on the font. The document looks fine in Preview and printed (even from Acrobat).
    Can anyone else reproduce this? I get this behavior consistently.

    Hi bdepaepe, I've had a look and I believe I have experienced the error you mean and solved it.
    The reason this occurs some of the time, but not always is because the source code is not the same each time, as the adverts change every refresh. The error only happens when two of the < div> tags of class 'banneritem' which are on top of each other have a height of 84px each as opposed to 80px (although even if this is the case the rendering issue doesn't always happen).
    The reason that some of the 'banneritem' < div> tags have a height of 84px is because inside them there is an <a> tag which contains an < img> tag, and the <a> tag has not been set to 'display: block;'. <a> tags are inline elements by default, so shouldn't be used to hold block level elements such as images unless the styles for the <a> tag include 'display: block;'.

  • Textarea ...  background-color:transparent   causing problem in IE7

    hello;
    when I use <textarea style="background-color:transparent " > IE7 does not accept input ... other browsers work fine;
    is there a way to get a transparent background for a textarea such that the textarea functions correctly in IE7 ( I haven't tested it in IE8 )?
    thanks,
    Shannon

    What happens if you remove the background tag altogether?
    I do this with my overflow css for text boxes and it leaves them transparent (as in: showing the page background) in Firefox, Safari Opera and IE 5, 6, 7 and 8.

  • Deinterlaced export causes artifacts in still images

    When I export to Adobe Media Encoder and select the "Deinterlace" option it does a great job of deinterlacing my interlaced footage. However, any still images in the mix and they immediately pick up artifacts. Any workarounds?

    Premiere is actually a horrible deinterlacer.  I'd do that outside of Premiere first, and edit in a progressive sequence.

  • Split screen causes artifacting in images - what is the solution?

    After creating a four image split screen (two frames on top, two frames on the bottom), the images in each box suffer from extreme artifacting. By that I mean the images breaks down. For example, grass that in the original images is clearly and cleanly visible, suddenly becomes very "noisy" once I have added it to the split screen.
    I have gone through several attempted solutions, but have all failed to solve the problem.
    The degradation is most noticable when I export to a Mpeg2 and burn to a DVD, but I have eliminated the possibility that it is breaking down in the Mpeg2 conversion. Instead, it seems to be happening within Final Cut Pro.
    Can anyone offer suggestions that might help?

    Patrick. Thanks very much for jumping in.
    For clarification, the images in the split screens are not photos. They are films. Four films in four boxes playing on the screen at the same time. Therefore, correct me if I'm wrong, your Photoshop advice doesn't work here. Also, I do not have Motion.
    I took a look at the suggestion in your final paragraph. I have Final Cut Pro HD 4.5, but nevertheless went through your suggested workflow. Ctrl-clicked on the sequence - selected settings - clicked on the Video Processing tab. I don't have a sampling setting as you indicate per se, but I did try changing the only apparently appropriate setting in FCP 4.5, which was to change from Render in 8-bit YUV to Render all YUV material in High Precision YUV. This took twice as long to render the sequence, but unfortunately had no positive effect.
    So, I am still in the position of having 4 great looking videos sequences, that I am trying to combine into one 4-squared split screen, but when I do so each of the four sequences deteriorates substantially.
    Do you have any other suggestions? I would be grateful for your experience.
    Powerbook G4, 867Mhz Mac OS X (10.4.3) 640 DRAM

  • JTabbedPane : JPanel transparent to 2D drawings

    Hi.
    I am using ptolemy/ptplot package for 2D graphics. I use a JTabbedPane to managae my plots by pages. Each plot is updated continuously by a Thread which get data from a datatbase.
    The problem: when a plot is refreshed in a hidden Tab, the plot appears also in the selected Tab. Only
    the data points appear, not the axes and the background. Result: I have a supperposition of "undesired
    plots" on the selected Tab.
    Please some one tell me how to solve this problem ?
    N.B.: I don't have a real experience with Java 2D.
    Christophe.

    Hi.
    I have found a workaround : my JTabbedPane now implements ChangeListener and "pauses" the plotting
    when a new Tab is selected. Only the plots on the selected Tab are refreshed the other are "paused".
    Thanks to hpsmartyz for the reply but I am new to Java2D, and I was not ready to modify the plot
    package I am using and implements his solution.
    Christophe.

  • Flash wmode opaque/transparent cause UI messup

    Hi,
      We are using Flex to develope flash tool, we have issues when embedded in iframe, if we are using default window wmode, everything is working fine, but unfortunately we can't use this mode because the iframe has a dropdown list and has to be above our flash layer, so we use opaque mode, we find that there are following two major issues:
    1. UI rendering is messed up when user scrolls up and down using the scroll bar
    2. user can't type in non-ascii characters
      The first issue is a killer for us, if anyone can shed some lights on it, that would be super, I really googled for a many hours without a good solution yet.

    I have definitely experienced the same issue(s). I was able to overcome these issues by upgrading to a later version of the Flex SDK and wrapping all of my content in the appropriate control for scrolling, eg when scrolling spark components, wrap them in a Group.
    There are a lot of weird bugs with Flash Player when using wmode:opaque. I can't scroll using my mouse wheel when using wmode:opaque, and weird things happen with text inputs. This is a major bug in Flash Player that really needs to be addressed.

  • Transparent JPanel

    Hello!
    I have a JFrame with a background painted on it and everything works fine so far, but when I create a JPanel in the JFrame the JPanels grey colour is laying on top of the background. So my question is how to make the JPanel transparent. I read about overriding the paintComponent method, but it didn't work, I'm probably doing something wrong.
    This is what I did:
    class Transparency extends JPanel {
         public Transparency() {}
         @Override
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
    contentPanel = new JPanel();
              contentPanel.setPreferredSize(new Dimension(mainFrame.getWidth(), 200));
              contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
              contentPanel.add(new Transparency());
              mainPanel.add(contentPanel);I would really appreciate some help!

    Newly created JPanel's have their opacity set to true. This means "I guarantee that I will paint all the pixels within my bounds." For many components this amounts to simply filling in the entire bounds of the component with the background color as the first thing they paint. So by setting the opacity to false the JPanel in question will no longer be a gray blob and will allow any components beneath it to show through.
    JPanel#setOpacity(false); The panel in question doesn't even need to be a custom subclass (read: delete that Transparency JPanel subclass).

  • N460GTX Cyclone 768D5/OC blue artifacts and stopped responding

    In the last month I have been having issues with my graphics card to the point that I can't play any game (at all, always stops responding), flash on websites cause video driver "stopped responding" error, vlc or media player videos cause stopped responding error, and any 3d screen saver preview in windows 7 causes artifacts and sometimes the stopped responding error.  I can still do anything 2D fine but always haver little blue artifacts all over the screen.  Current drivers are Nvidia 266.58, I have tried MSI drivers, Nvidia 260.* drivers and a set of older Nvidia drivers that supposedly didn't have the stopping issues but all had problems even after fully wiping the old drivers on every install.
    Given the power issues I have seen in past threads I hooked up my Kill-a-watt again (I always baseline my systems on burn in with that), and I am finding my Wattage draw hasn't changed.  Kill A Watt measures 188W avg Draw, Peak 250W.  All drives set on RAID to spin up sequentially so I don't get the max draw you'd expect.  I ran this with superPi, prime95 and memtest and all run fine with max draw I saw at 250W.  I tried to run 3d benchmark tests but like all 3d apps they all crash after video card not responding error.  When building this I carefully specd out the power supply with conservative numbers and multiple online calculators, this PS should be able to handle adding 2 more 1TB drives as long as I don't do SLI (don't have room in case anyway with RAID controller).
    I have tried all I can think of to resolve this but nothing helps and I'm thinking it's got to be an issue with the card since nothing in my config has changed.  Is it the card for sure and will need RMA?
    Here are my specs:
    Asus P6T WS Pro Mobo
    Intel Core i7-930 Bloomfield 2.8GHz LGA 1366 130W
    MSI N460GTX Cyclone 768D5/OC GeForce GTX 460 (Fermi) 768MB
    6 GB DDR3 Kingston PC3-10700 8-8-8-24 timing
    Kingston SSDNow V Series 64GB
    Areca ARC-1120 RAID controller (configured RAID6)
    4x Hitachi Deskstar HD31000 1TB 7200 RPM SATA
    2x Samsung 1TB 7200 SATA
    LG Black 10X Blu-ray Burner - Bulk SATA WH10LS30
    Power:
    XFX Black Edition P1-750B-CAG9 750W ATX12V v2.2 / ESP12V v2.91 SLI Ready CrossFire Ready 80 PLUS SILVER
    Single +12V rail, +3.3V@24A, +5V@30A, +12V@62A, [email protected], [email protected]
    From XFX site regarding this PS:
    Tight voltage regulation (±3%)
    Single, high power +12V rail (up to 62A/744W)
    DC to DC voltage Regulator modules for +3.3V and +5V
    High quality Japanese brand capacitors (105°C)
    Solid polymer caps provide enhanced reliability and stability
    Quiet 135mm ball bearing fan provides superior cooling
    Supports multiple high-end graphic adapters (NVIDIA SLI & ATI CrossFire Ready)
    Detachable modular cables
    Energy Star 4.0 and RoHS compliant

    Can you test the card in another system, yours or a friends?

Maybe you are looking for