How to make JPanel to transparent?

Dear all, anyone here know how to make 2 JPanel to transparent and overlabbing? i try to use opaque(boolean), but i fail to do it, here is my code, i really need ur help.......thankx a lot
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JApplet
     public void init()
          DrawBase db=new DrawBase();
          DrawGraph dg=new DrawGraph();
          Container container=getContentPane();
          db.setOpaque(true);
          dg.setOpaque(true);
          container.add(db,BorderLayout.CENTER);
          container.add(dg,BorderLayout.CENTER);
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DrawBase extends JPanel
     public DrawBase()
     public void paintComponent(Graphics g)
          super.paintComponent(g);
          g.setColor(new Color(0,255,0));
          g.drawOval(50,50,50,50);
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DrawGraph extends JPanel
     public DrawGraph()
     public void paintComponent(Graphics g)
          super.paintComponent(g);
          g.setColor(new Color(255,0,0));
          g.drawOval(20,10,10,10);

Hi,
Dear all, anyone here know how to make 2 JPanel to
transparent and overlabbing? i try to use
opaque(boolean), but i fail to do it, here is my code,
i really need ur help.......thankx a lot
Well, the transparent part is easy. You should be calling setOpaque(false) rather than setOpaque(true). This will eliminate background painting of the JPanels.
The overlapping can be accomplished in multiple ways, but NOT using BorderLayout. You'll either want to do as one person suggested and use no layout manager and position things absolutely, or as another suggested and use JLayeredPane.
Personally, I would suggest a third approach that uses a single JPanel to do all of the painting. Something like this would work nicely:
public class DrawPanel extends JPanel {
    public DrawPanel() {
        setOpaque(false);
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        drawBase();
        drawGraph();
    public void drawBase() {
        g.setColor(new Color(0,255,0));
        g.drawOval(50,50,50,50);
    public void drawGraph() {
        g.setColor(new Color(255,0,0));
        g.drawOval(20,10,10,10);
}Regards,
Shannon Hickey (Swing Team)

Similar Messages

  • How to make a completely transparent button in Flash Builder

    I am making a mobile application, and I am wondering how to make a completely transparent button. I've tried using
    <s:Button x="-5" y="0" width="410" height="1504"
                                    skinClass="spark.skins.mobile.TransparentNavigationButtonSkin" click="navigator.pushView(Sun)"/>
    But it still has one line on the side. I need a way to make it completely transparent.
    Thanks,
         8th grade student

    Try this alpha="0.001"
    Also add useHandCursor="true" and buttonMode="true" if you wish to have the hand cursor appear on hover.
    example  x="10" y="10" width="169" height="54" label="Button" alpha="0.001" useHandCursor="true" buttonMode="true" 
    HTH

  • Anyone know how to make an "Index Transparent" gif

    I have successfully made transparent PNGs and GIFusing an Alpha transparency but now I need to make images which would be the same as ueing fireworks / Photoshop to make a colour transparent. i.e. indexed transparency.
    Does anyone know how to do this.
    My code is as follows :
    // configure all of the parameters
    String text = "ABC abc XYZ xyz ["+ new Date()+"]";
    String font_file = "./tst/Maiandb.TTF";
    font_file = request.getRealPath(font_file);
    float size = 30.0f;
    Color background = Color.white;
    Color color = Color.black;
    Font font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(font_file));
    font = font.deriveFont(size);
    buffer = new java.awt.image.BufferedImage(1,1,java.awt.image.BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = buffer.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    java.awt.font.FontRenderContext fc = g2.getFontRenderContext();
    java.awt.geom.Rectangle2D bounds = font.getStringBounds(text,fc);
    // calculate the size of the text
    width = (int) bounds.getWidth();
    height = (int) bounds.getHeight();
    // prepare some output
    buffer = new java.awt.image.BufferedImage(width, height, java.awt.image.BufferedImage.TYPE_INT_ARGB);
    g2 = buffer.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2.setFont(font);
    // actually do the drawing
    Color transparent = new Color(0, 0, 0, 0);
    g2.setColor(transparent);
    g2.fillRect(0,0,width,height);
    g2.setColor(color);
    g2.setComposite(AlphaComposite.SrcOver);
    g2.drawString(text,0,(int)-bounds.getY());
    File file = new File ("./jsp1/tst/fred1.gif");
    com.gif4j.light.GifImage gifImage = new com.gif4j.light.GifImage();
    com.gif4j.light.GifFrame gifFrame = new com.gif4j.light.GifFrame(buffer);
    gifImage.addGifFrame(gifFrame);
    GifEncoder.encode(gifImage, file);Thanks in advance

    ^^EDIT^^
    System admins updated iMac to OS X Mountain Lion (10.8.4).

  • How to make opaque white transparent?

    I have a JPEB, black words, hand lettered, on white.
    When I place it into an InDesign doc, on a solid color, the white background, being opaque, covers the solid color.
    How do I make that opaque white into a transparent background? Two manuals do not give me a clue.
    Thanks.

    larry red miller wrote:
    So if I go back to the original .psd file, a transparency option will
    materialize in one of the menus?
    No.. Photoshop transparency is automatically seen in Indesign for .psd files. All you need to make the background transparent in Photoshop.
    larry red miller wrote:
    Well, uhh, that is what I wanted to k now. Where do I find those methods?
    If you Google for "remove background in Photoshop" you will literally find THOUSANDS of tutorials.

  • How to make JPanel as JTable Cell Editor (Urgent help needed)

    Hi!
    I want to make JPanel (with a JTextField, 3 JLabels and 1 JTextArea) as cell editor for one column. Can somebody help me on this?
    Does anybody have any sample code? I will greatly appreciate ur help.
    Thanks,
    Snehal

    Okie. In "How to use JTables" page found in the JAVA website (there is a link from the JTable section of the JAVA API documentation), there is a sample code for a sample color chooser. What this does is, adds a button with its action listener set to pop up a color chooser window. In this, rendering is still through a JLabel.
    This example would be of good help to you. Plus, this example gives me a feeling that what u ask is possible.

  • How to make a Frame transparent?

    Hi everyone:
    I want to make a Frame transparent,it is possible?I find all the API but no result : (
    More, I want to increate my Frame's Height ,but it can't work. code is:
    Frame f=new Frame("Test");
    for(int i=0;i<6;i++){
    f.setSize(40,i * 10);
    }If I change to code to
    f.setSize(40,10);
    f.setSize(40,20);
    f.setSize(40,30);
    ...................It can work well.But why ? It is so complicated . : (
    Please help me

    More
    How to add a hyperlink Text in Frame? When I click it which can open a web site?

  • How can make Jpanel response click event?(help!)

    in a program i want to make jpanel response mouseclicked event, but jpanel class does not provide addActionListener(). through which way? i am able to arrive at the purpose! (create a new class extends jpanel, how to do?)
    thank a lot!!!

    Hello,
    have a look:import java.awt.Color;
    import java.awt.event.*;
    import javax.swing.*;
    public class ClickPanel extends JPanel implements MouseListener
         public static void main(String[]args)
              JFrame frame = new JFrame("Click-Panel");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.getContentPane().setLayout(null);
              frame.getContentPane().add(new ClickPanel());
              frame.setBounds(200,200,400,400);
              frame.setVisible(true);
         public ClickPanel()
              addMouseListener(this);
              setBounds(200,200,100,100);
              setBackground(Color.CYAN);
         public void mouseClicked(MouseEvent e)
              System.out.println("clicked");
         public void mouseEntered(MouseEvent e)
              System.out.println("entered");
              setBackground(Color.ORANGE);
         public void mouseExited(MouseEvent e)
              System.out.println("exited");
              setBackground(Color.CYAN);
         public void mousePressed(MouseEvent e)
              System.out.println("pressed");
         public void mouseReleased(MouseEvent e)
              System.out.println("released");
    }regards,
    Tim

  • [iPhone] How to make one color transparent on a UIImage?

    On my iPhone app I have a UIImage instance. I want to get a derived a UIImage that is the result of the first UIImage where one of its colors (e.g. magenta) is made transparent. How can I do this?
    NOTE: I cannot make the color transparent in Photoshop, the UIImage is created on the fly by the user. I need to do the "postprocessing" on the phone itself, after the user is done "drawing" the image.

    jubgb
    I still do not know your version of Premiere Elements and  your computer operating system, but here is a plan that would probably work for Premiere Elements 11, 12/12.1, and 13/13.1 on Windows 7, 8, or 8.1 64 bit.
    But you say that you are starting with a black and white image. If you could start with the color version of the image, I think we have a promising path to have the fake blood appear in color on a black and white image.
    This would be done by applying the Color Pass effect to the color photo version. Color Pass Effect is  found under fx Effects/Image Control/Color Pass.
    Then you would edit the Color Pass effect under Applied Effects Tab/Appied Effects Palette/Color Pass Panel expanded. But I find that the most effective editing of that effect is done using the Setup whose icon appear to the right of the Color Pass Panel.
    Have you used the Color Pass effect before?
    https://helpx.adobe.com/premiere-elements/using/effects-reference.html
    I will offer how to suggestion for its use if interested. As for starting with the black and white, then I need to think about that some more.
    ATR

  • How to make component semi-transparent?

    Hi,
    I want to make a component semi transparent so that i can see through component below that? is it possible in swing? if it is how can i do that?
    Thanks,
    Sato.

    I've had limited success by specifying a background color using an alpha value.
    setBackground( new Color(123, 123, 123, 128) );

  • How to make a JWindow transparent

    hi
    as my question describes i wants to make a transparent window. please help me. example code should be appreciated .
    thanx in advance.

    That's an imitation of the transparent window.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    public class Test {
        JScrollPane scroll;
        JPanel p=new JPanel(new BorderLayout());
        Robot robot=new Robot();
        public Test()  throws Exception {
            final TransparentFrame frame=new TransparentFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(p);
            JButton b=new JButton("Test");
            b.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
    /*                TransparentFrame frame1=new TransparentFrame();
                    frame1.setBounds(100,100,100,100);
                    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame1.setVisible(true);*/
            frame.getContentPane().add(new JLabel("Test"));
            frame.getContentPane().add(b);
            frame.setBounds(100,100,200,200);
            frame.show();
        public static void main(String[] args) throws Exception {
            new Test();
    class TransparentFrame extends JFrame {
        Robot robot;
        BufferedImage screenImg;
        Rectangle screenRect;
        MyPanel contentPanel=new MyPanel();
        boolean userActivate=false;
        public TransparentFrame() {
            super();
            createScreenImage();
            this.setContentPane(contentPanel);
            this.addComponentListener(new ComponentAdapter() {
                public void componentHidden(ComponentEvent e) {}
                public void componentMoved(ComponentEvent e) {
                    resetUnderImg();
                    repaint();
                public void componentResized(ComponentEvent e) {
                    resetUnderImg();
                    repaint();
                public void componentShown(ComponentEvent e) {}
            this.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                public void windowClosed(WindowEvent e) {
                public void windowOpened(WindowEvent e) {
                public void windowIconified(WindowEvent e) {
                public void windowDeiconified(WindowEvent e) {
                public void windowActivated(WindowEvent e) {
                    if (userActivate) {
                        userActivate=false;
    //                    boolean f=TransparentFrame.this.isShowing();
    //                    if (f)
                            TransparentFrame.this.setVisible(false);
                        createScreenImage();
                        resetUnderImg();
    //                    if (f)
                            TransparentFrame.this.setVisible(true);
                    else {
                        userActivate=true;
                public void windowDeactivated(WindowEvent e) {
        protected void createScreenImage() {
            try {
                if (robot==null)
                    robot=new Robot();
            catch (AWTException ex) {
                ex.printStackTrace();
            Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
            screenRect=new Rectangle(0,0,screenSize.width,screenSize.height);
            screenImg=robot.createScreenCapture(screenRect);
    /*    public void show() {
            resetUnderImg();
            super.show();
        public void resetUnderImg() {
            if (robot!=null && screenImg!=null) {
                Rectangle frameRect=getBounds();
                int x=frameRect.x+4;
                contentPanel.paintX=0;
                contentPanel.paintY=0;
                if (x<0) {
                    contentPanel.paintX=-x;
                    x=0;
                int y=frameRect.y+23;
                if (y<0) {
                    contentPanel.paintY=-y;
                    y=0;
                int w=frameRect.width-10;
                if (x+w>screenImg.getWidth())
                    w=screenImg.getWidth()-x;
                int h=frameRect.height-23-5;
                if (y+h>screenImg.getHeight())
                    h=screenImg.getHeight()-y;
                contentPanel.underFrameImg=screenImg.getSubimage(x,y,w,h);
    class MyPanel extends JPanel {
        BufferedImage underFrameImg;
        int paintX=0;
        int paintY=0;
        public MyPanel() {
            super();
            setOpaque(true);
        public void paint(Graphics g) {
            super.paint(g);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(underFrameImg,paintX,paintY,null);
    }

  • How to make a semi-transparent layer?

    Hello everyone,
    I am making my own website with Dreamwaver. I am a totally
    new user and have no IT background. So could anyone here kindly
    help me with my question:
    In the main page I would like to use two layers with images
    inserted. The second one will be a semi-transparent image which is
    made in Fireworks. I would like to let this layer cover the first
    one. Because it's semi-transparent, so i should still be able to
    see the underlying image... I did all this, but finally in the IE
    the second layer is NOT transparent at all.
    I don't know where the problem is. Please, if anyone knows
    the solutions or have any suggestion, let me know!
    Thanks!
    Inca

    I'll show it to you my way:
    1. Type the text and click the layer mask icon. The layer mask should be all white and have a small border. That indicates the mask ist active.
    The foreground color should be black and the background color white.
    2. Choose the gradient tool. Open the gradient window. Choose the first gradient, "foreground to background" = black to white.
    Change the white color to gray.
    3. Check the layer mask > is it active?
    Apply the gradient from right to left over your text.
    See the thin line in the screenshot.
    4. On your layer mask appears the gradient, left starting with gray and right ending with black.
    The advantage of this method is that you can change your text without  modifying the gradient.
    The black color on the layer mask hides the text, the gray color makes the text more or less visible and white color means full visible.
    Hope it helps.
    miss marple

  • How to make form field transparent?

    I would like to change the blue color of the fields to transparent. How can I do it?

    Do you mean the highlight color? You can disable it via the Preferences window (under Forms).

  • How to make Layers NOT transparent ??

    Hey i am making an animation
    Its of a guy walking but he is transparent. I have already got like 100+ frames of him walking but he is transparent and therefore i cannot put a background or it shows through.
    Is there anyway i can make all existing frames nontransparent.

    The easiest way is to create a new layer and fill it with what ever color you choose then when your ready for a new layer just duplicate that layer with ctrl-j or cmd-j (former is windows and later is mac)

  • How to make the stage transparent for SWF file being used in Dreamweaver

    I have a SWF file in my Dreamweaver site, that plays correctly. The problem is that the stage is white and we would like it to be transparent. Searching the archives the following advice was given:
    in your html embedding code you need to set the wmode parameter to be "transparent"
    I'm wondering if this is the code in Dreamweaver or is this done in Flash. I'm working with CS5. Below is the code that matches the SWF file in Dreamweaver. I did change the wmode value from "opaque" to "transparent" and it didn't work.
    Thanks for any assistance.
    Sherri
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="650" height="400" id="FlashID" title="Convergence Gathering Title">
                 <param name="movie" value="Flash/gold_dust_title.swf" />
                 <param name="quality" value="high" />
                 <param name="wmode" value="opaque" />
                 <param name="swfversion" value="6.0.65.0" />
                 <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                 <param name="expressinstall" value="Scripts/expressInstall.swf" />
                 <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                 <!--[if !IE]>-->
                 <object type="application/x-shockwave-flash" data="Flash/gold_dust_title.swf" width="650" height="400">
                   <!--<![endif]-->
                   <param name="quality" value="high" />
                   <param name="wmode" value="opaque" />
                   <param name="swfversion" value="6.0.65.0" />
                   <param name="expressinstall" value="Scripts/expressInstall.swf" />
                   <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                   <div>
                     <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
                     <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
                   </div>
                   <!--[if !IE]>-->
                 </object>
                 <!--<![endif]-->
               </object>

    Yes, change this to "transparent" in ALL the places where wmode is shown
    <param name="wmode" value="opaque" />
    Second, be sure that there is in fact nothing covering the entire stage, like a big white rectangle.
    Also, what is directly behind the .swf once it's on the Web page? If the background color of that page or the <div> that the .swf is in is white..... well then then .swf can have a transparent background but then the white from the Web page just shows thru.... so there's still a white background.
    Be sure there is a non-white background on the Web page...
    Window Mode (wmode) - What's It For?
    There are three window modes.
    Window
    Opaque
    Transparent
    By default, the Flash Player gets its own hWnd in Windows. This means that the Flash movie actually exists in a display instance within Windows that lives above the core browser display window. So though it appears to be in the browser window, technically, it isn't. It is most efficient for Flash to draw this way and this is the fastest, most efficient rendering mode. However, it is drawing independently of the browser's HTML rendering surface. This is why this default mode (which is equivalent to wmode="window") doesn't allow proper compositing with DHTML layers. This is why your JavaScripted drop-down menus will drop behind your Flash movie.
    In windowless modes (like opaque), Flash Player doesn't have a hWnd. This means that the browser tells the Flash Player when and where to draw onto the browser's own rendering surface. The Flash movie is no longer being rendered on a higher level if you will. It's right there in the page with the rest of the page elements. The Flash buffer is simply drawn into whatever rectangle the browser says, with any Flash stage space not occupied by objects receiving the movie's background color.
    Best wishes,
    Adninjastrator

  • How to make an image transparent?

    Hi everybody,
    I need to build a complex chart in my applet, for this I want at first to create some painted area and then to put a map over it. The map is an image, which consists basically of black lines for state borders, main rivers and lakes on the white background. What I need is to put just these black lines, not the white background which will kill previously painted area.
    Can anyone give me an idea?
    Thanks,
    Alexandre

    Here's a class that implements this. I need a "transparent" object that has a big red arrow that I can point at stuff, so it gets its parents context and paints that then paints the red arrow stuff. The only problem with this is that it is not a glass pane. The "transparent" object must be contained in one object so you can only "paint over" one object.
    public class KiaTutorialArrow extends Panel
         public static final int WEST = 0, EAST = 1, NORTH = 2, SOUTH = 3;
         private int direction = 0;
         private Polygon arrow;
         //public Color foreground;;
         ////////constructors/////////////////////////////////////
         public KiaTutorialArrow()
              super();
              setSize(40,25);
         ////////////////get and set functions////////////////////
         public int getDirection()
              return direction;
         public void setDirection(int index)
              this.direction = index;
              arrow = null;
              repaint();
         public String getName()
              return super.getName();
         public void setName(String name)
              super.setName(name);
              repaint();
         public Color getBackground()
              return super.getBackground();
         public void setBackground(Color c)
              super.setBackground(c);
              repaint();
         public void paint(Graphics g)
              // TRANSPARENCY IS THE DEFAULT     
              Container c = getParent();
              Graphics graphics = g.create(- getLocation().x, - getLocation().y, c.size().width, c.size().height);
              c.paint(graphics);
              g.setColor(Color.red);
              switch (direction)
                   case WEST: drawWest(g); break;
                   case EAST: drawEast(g); break;
                   case NORTH: drawNorth(g); break;
                   case SOUTH: drawSouth(g); break;
                   default: return;
         private void drawWest(Graphics g)
              if (arrow == null)
                   arrow = new Polygon();
                   arrow.addPoint(2,12);
                   arrow.addPoint(12,5);
                   arrow.addPoint(12,8);
                   arrow.addPoint(27,8);
                   arrow.addPoint(27,17);
                   arrow.addPoint(12,17);
                   arrow.addPoint(12,20);
              g.drawPolygon(arrow);
              g.fillPolygon(arrow);
         private void drawEast(Graphics g)
              if (arrow == null)
                   arrow = new Polygon();
                   arrow.addPoint(7,8);
                   arrow.addPoint(22,8);
                   arrow.addPoint(22,5);
                   arrow.addPoint(32,12);
                   arrow.addPoint(22,20);
                   arrow.addPoint(22,17);
                   arrow.addPoint(7,17);
              g.drawPolygon(arrow);
              g.fillPolygon(arrow);
         private void drawNorth(Graphics g)
              if (arrow == null)
                   arrow = new Polygon();
                   arrow.addPoint(8,0);
                   arrow.addPoint(15,10);
                   arrow.addPoint(12,10);
                   arrow.addPoint(12,25);
                   arrow.addPoint(3,25);
                   arrow.addPoint(3,10);
                   arrow.addPoint(0,10);
              g.drawPolygon(arrow);
              g.fillPolygon(arrow);
         private void drawSouth(Graphics g)
              if (arrow == null)
                   arrow = new Polygon();
                   arrow.addPoint(8,25);
                   arrow.addPoint(0,15);
                   arrow.addPoint(3,15);
                   arrow.addPoint(3,0);
                   arrow.addPoint(12,0);
                   arrow.addPoint(12,15);
                   arrow.addPoint(15,15);
              g.drawPolygon(arrow);
              g.fillPolygon(arrow);
    }

Maybe you are looking for

  • Macbook air 2012 wifi problem

    Hi, I have just bought a new macbook air and Im finding that the wireless keeps dropping at random times, it is not the router as I have a connection on my old 2008 Macbook, windows laptop and ipads etc. I have done some browsing on the net and found

  • Satellite L655D S5109 display problems

    So this is what happened before: 1. I don't know if this is related but like two months ago there was a day where the batery would't charge. if i plugged it to a power source the % of the batery would remain the same, if i disconnect it it would go d

  • IDVD keeps crashing when I try to burn a disc

    When I try to burn the disc having put together slideshows on the Magic iDVD option it keeps crashing and a message to Apple come up on the screen.  Can antone help please??

  • I click apply update on the about firefox window but then cancelled it, now it wont work

    Firefox informed me of an update, i applied it but cancelled it when it asked for the admin password. I am now trying to apply it about it just closes down and restarts with out it being applied. My current version is 4.0.1 when i go to the about fir

  • How much to partition on External HD for Time Machine?

    Hi- I have an 80GB MacBook. I have a new External HD that has 500GB. How much space should I partition so that I can run Time Machine? WIll 100GB do the trick,or should I use more? Thanks for your advice. -Tim