I have some JButtons in a JFrame (its layout is null). The background Color of the buttons are set Black. I have made the JFrame Transparent by using this code.
AWTUtilities.setWindowOpacity(this, 0);
But the problem is it also makes all the buttons transparent as well. I don't want that. I want to see the buttons remaining black but the other portions of the JFrame becoming transparent (so that I can see the desktop background). Please someone help me.
Thanks in advance.
What about using the call button.setOpaque(true) ?
Yeh, the problem was opacity set to zero. Any non-zero value with all button.setOpaque(true), will display buttons clearly. For me, AWTUtilities.setWindowOpacity(frame, 0.7f) works too.
Related
I want my JPanel to be semi transparent. This panel is animated and has the motion of a dropdown list. I have used the Color(r,g,b,a) constructor to achieve the transparency, however the transparency only takes effect as the panel returns to its original position. For example, as it is moving downwards it is not transparent at all, however when moves up, it spontaneously becomes transparent.
How do I fix this problem?
detailPanel.setBackground(new Color(50,50,50,220));
detailPanel.setLayout(null);
detailPanel.setBounds(0,posY,1200,750);
Check out Backgrounds With Transparency for the cause of the problem (you can't use a transparent Color on an opaque background) and a couple of solutions to fix the problem:
make the component non-opaque and paint the background yourself
use the AlphaContainer class so it can do the painting of the background for you
I need to create a panel which is partially transparent and which blurs what appears behind the panel. Such as the title bar in widows 7. Help me if someone knows how to do this very simply
I'm struggling with two Java GUI things at the moment.
This is the situation: I'm designing a word game using Swing components. I have a main JFrame where everything is placed (my GUI class extends JFrame). There are two things I want to do:
1st: I would like to set an image as the background image of the main frame, it has to be displayed behind all components. i've searched around but haven't found a working solution. I tried making an extended BackGroundPanel class but when I create an instance of BackGroundPanel I have no idea how to make it the background of the frame... I also haven't find a good way to load in an image from an 'images' directory in my src folder...
2nd: when the program starts the user is greeted with an undecorated JDialog, the main frame needs to be disabled, which I figured out, but I would also like to make it a bit darker. I believe it should be possible with the GlassPane, but I have no idea how to set the GlassPane to cover the panel with one color...
Help will be much appreciated, I don't think I have any helpful code to share, but I think the situation explained above gives a general idea? I would just like someone to get me on track with this so I can further work this out! Thanks!
My Main class extends JFrame and it has a BorderLayout.
Add your BorderLayout to a JPanel having, e.g. GridLayout().
This AnimationTest illustrates painting a background image behind components.
This Translucent example illustrates using an AlphaComposite; see also this AlphaTest.
Well for your first question, you can use a label and set the icon of it:
JLabel lblimage = new JLabel("");
lblimage.setIcon(new ImageIcon(Main.class.getResource("/img/background.png")));
lblimage.setBounds(0, 0, 794, 711); //size of frame
contentPane.add(lblimage); //bottom
contentPane.add(component1); //middle low
contentPane.add(component2); //middle top
contentPane.add(component3); //top
as for your second question.. you could possibly do the same thing, just use an image with a solid color and lower the transparency, and place on top of your other components (not sure on this solution though).
I have this idea that I want to implement into my project.
I know it is doable, but I do not know where to start.
I have a JPanel,
in there will be a Jbutton , a JLabel, and a ComboBox, and a JtextArea.
Originally, there is only the JtextArea and JButton on my panel.
When I hit the button, the Combobox, and JLabel will slide in or fade in, or drop down, or event rotate in.
So how would I accomplish this, I know I have to use graphic g, repaint(). It is easy to do the Jlabel but what about the combobox.
Should I add the combobox and Jlabel into a separate Jpanel and make that panel animated in. but even that, I do not know how to make this panel in motion.
Please help me on this, and example would be appreciated
Thank you!
To get started, you'll probably need to research these terms:
Slide layout (thanks #Andrew Thompson)
setLocation
TimerTask (I think, or maybe just Timer)
clobbering graphics objects
Once you know about that stuff, you'll be in a position to make the design decisions that you're asking about.
It sounds like you'll have a child panel with a slide layout. Try not to use null layouts when possible.
You'll set its location or style per each tick in a timer task.
If you're setting a style, you'll need to clone your graphics object to avoid "clobbering" it - that is, work on a copy of the graphics object, so the original isn't changed or repainted accidentally while you're working on it.
I need to create a panel which should be invisible but the components inside it (for example, JTextArea, JButton, etc.) should be visible. When I click on the invisible panel, it should become visible.
I can only use JRE 1.4 and nothing more than that. :(
Any idea how to create such a transparent panel???
Transparancy is controlled with
setOpaque(false)
JComponent.setOpaque(false) is the way to go.