JPopupMenu ignores setOpaque(false) near screen edges
Dear group
I try to paint a custom JPopupMenu with transparency, but this is ignored when the popup is opened so it overlaps near screen edges (bottom and right side). This is also the case if the popup overlaps the Microsoft Windows toolbar at the bottom.
I may be able to emulate JPopupMenus using custom components in a JLayeredPane, but can anyone explain the above behaviour?
Thanks and Best Regards,
Aksel, Denmark
Environment: j2sdk-se 1.6.0_10 and windows xp
Example:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
public class TransparencyPopupNearBorderTest {
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds(new Rectangle(screenSize));
frame.setUndecorated(true);
frame.setPreferredSize(screenSize);
frame.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
JPopupMenu popup = new JPopupMenu();
popup.setOpaque(false);
JLabel label = new JLabel("TRANSPARENT");
label.setFont(new Font("Helvetica", Font.PLAIN, 42));
popup.add(label);
popup.setLightWeightPopupEnabled(false);
popup.show(frame, e.getX(), e.getY());
frame.getContentPane().setBackground(Color.BLUE);
frame.pack();
frame.setVisible(true);
}
Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
I don't know if transparency painting has changed in 1.6.0_10. Prior to that I believe transparency can only be achieved in lightweight components (ie. Swing does all the painting). JFrame, JWindow and JDialog are not lightweight because they use OS components.
In the case of a popup, it is lightweight when entirely contained within its parent frame. But a lightweight popup can not be painted outside the bounds of the frame so a JWindow (I believe) is used as the popup, which can't be transparent.
Similar Messages
-
Extending DefaultTreeCellRenderer, Jlabel setOpaque(false) no effect
Hi, im using the code below, but my JLabel component.setOpaque(false) is having no effect, is this possible?
private class MyRenderer extends DefaultTreeCellRenderer {
ImageIcon tabIconOnline, tabIconOffline;
String status;
public MyRenderer() {
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
JLabel jl = (JLabel)super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
jl.setOpaque(false); // not working
setOpaque(false); // not working
tree.setOpaque(false); // not working
setBackgroundSelectionColor(MyGUI.ITEM_SELECTION_COLOUR);
setBackgroundNonSelectionColor(null); // not working
setBorderSelectionColor(new Color(10, 10, 255));
return jl;
}heres the full code, im using:
private class MyRenderer extends DefaultTreeCellRenderer {
ImageIcon tabIconOnline, tabIconOffline;
String status;
public MyRenderer() {
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
JLabel jl = (JLabel)super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
//jl.setOpaque(false);
// setOpaque(false);
tree.setOpaque(false);
if (node == rootNode) {
setForeground(new Color(255, 255, 255));
} else if ((node == nodeFriends) ||(node == nodeRecent)||(node == nodeIgnored)) {
if (leaf) {
setIcon(createImageIcon("images/icon_noChildren.gif"));
setForeground(new Color(255, 255, 255));
setToolTipText("To add a Friend , Right click then 'Add A Friend'");
} else if (node.getParent() == nodeFriends) {
Friend friend = (Friend)(node.getUserObject());
if (friend.getStatus().equals("online")) {
setForeground(new Color(255, 255, 255));
setIcon(createImageIcon("images/icon_online.gif"));
setToolTipText("Is " + friend.getStatus());
} else {
setIcon(createImageIcon("images/icon_offline.gif"));
setToolTipText("Is " + friend.getStatus());
setForeground(new Color(255, 255, 255));
} else if (node.getParent() == nodeRecent) {
setForeground(new Color(255, 255, 255));
} else if (node.getParent() == nodeIgnored) {
setForeground(new Color(255, 255, 255));
setToolTipText("You are ignoring this user");
if (sel) {
setForeground(Color.black);
//jl.setBackground(null);
setBackgroundSelectionColor(MyGUI.ITEM_SELECTION_COLOUR);
//setBackgroundNonSelectionColor(null);
setBorderSelectionColor(new Color(10, 10, 255));
return jl;
} -
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! -
[Kind of Solved] Screen edges in Compiz?
I am using XFCE+Compiz.
When I right-click or scroll on any edge of the screen, nothing happens. I know that this is because of the screen edges set by Compiz.
However, when I installed Compiz in Ubuntu this summer, it didn't have this behavior. What does Ubuntu do to turn off the edges? Is there some compile flag or something?
Last edited by pogeymanz (2009-09-10 22:43:45)Well, that sucks... I don't know why it doesn't work. I don't think I have anything bound to most edges. I have expo bound at top-left corner and scale bound at top-right.
Ah, okay. It's the Desktop Wall plugin. The edge flipping when you drag a window across veiwports is what was messing it up. So, I at least turned of the top and bottom edges, but I need the left and right to drag windows. It's a lot better now, even if not totally perfect.
Last edited by pogeymanz (2009-09-10 22:41:22) -
Why does setOpaque(false) on Mac interfere with functionality of JSlider?
Hello, here is an SSCCE with a slider that works normally on my PC:
import javax.swing.*;
public class Foobar extends JApplet
public void init()
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.add(new JSlider());
setContentPane(panel);
}But on my sister's Mac, the slider functionality is broken: one cannot drag the thumb with the mouse. To move the thumb, she has to click on the rail. If I comment out the setOpaque(false) call, then everything works fine.
I need that setOpaque call and I want the program to work both on Mac and PC. Why does it break on the Mac and how to fix it? Thank you for your insight. MarkSo then you haven't actually ran that SSCCE on a MAC then? No, no, she ran it on her Mac, my sis. I asked her to run it several times, and she definitely cannot move the thumb. Now, if I comment out the setOpaque(false), then she can move it all right.
But, I found a workaround. I did not realize that before, that Apple actually does include the "cross-platform" look and feel, not only their own Aqua. On the Sun website, it sort of implies that Apple only has Aqua, but on Apple website, I found they also support the cross-platform look.
And voila, I changed to the cross-platform, and now, everything works. Not only the sliders in non-opaque panels, but I had also a HUGE number of other problems getting my app to work on the Mac, and now, with the cross-platform look, they all disappeared!!
Thank you.
Mark -
JPanel setOpaque(false) isn't transparent ?
Hi,
I've set a JPanel as the only thing added to a JFrame container. I've set a picture to this JPanel by using the following code
JPanel temp = new JPanel()
public void paintComponent(Graphics g)
Dimension d = getSize();
g.drawImage(icon.getImage(), 0, 0, d.width, d.height, null);
setOpaque( false );
super.paintComponent(g);
};Now I've added another JPanel onto this one. I've set its background to RED, so there is a red square over my picture on my JFrame. However I want this JPanel to be fully transparent, so you can't actually see it at all, so the picture behind it on the original JPanel shows through.
But when I use setOpaque(false), I just get a gray square instead of a red one, it doesn't show anything through at all.
Anyone know why this would be ?
ThanksHere you go, the background picture is not shining through. You'll have to change the jpg name to whatever you want to use.
Thanks
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
public class OneToOneChat extends JFrame
protected JPanel leftZone, rightZone, totalZone;
protected JTextPane bottomLeftZone, topLeftZone;
protected JScrollPane topScroll, bottomScroll;
public static void main(String args[])
new OneToOneChat();
public OneToOneChat()
setSize(400,400);
setTitle("My Opaque Problem");
setLocation(200,200);
setResizable(false);
Container con = getContentPane();
leftZone = new JPanel(new BorderLayout());
rightZone = new JPanel(new BorderLayout());
totalZone = new JPanel(new BorderLayout());
topLeftZone = new JTextPane();
bottomLeftZone = new JTextPane();
topScroll = new JScrollPane(topLeftZone, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
topScroll.setPreferredSize(new Dimension(250,150));
bottomScroll = new JScrollPane(bottomLeftZone,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
bottomScroll.setPreferredSize(new Dimension(250,150));
rightZone.setOpaque(false);
rightZone.setBackground(Color.RED);
rightZone.setBorder( new LineBorder(Color.GREEN) );
rightZone.setPreferredSize(new Dimension(250,300));
leftZone.add(topScroll, "North");
leftZone.add(bottomScroll,"South");
totalZone.add(leftZone,"West");
totalZone.add(rightZone,"East");
final ImageIcon icon = new ImageIcon("ripple.jpg");
JPanel temp = new JPanel()
public void paintComponent(Graphics g)
Dimension d = getSize();
g.drawImage(icon.getImage(), 0, 0, d.width, d.height, null);
setOpaque( false );
super.paintComponent(g);
temp.setBorder(new EmptyBorder(8,8,8,8));
temp.add(totalZone);
con.add(temp);
pack();
setVisible(true);
} -
SetOpaque(false) doesn't work
Hi,
I'm looking for help to have background transparent panels. I tried to use JPanel with setOpaque(false), but I still have a lightGrey background ! Is it normal ??? I don't think so. Could anyone help me please...Thanks for your answers.
I get rid of JComponent, I prefer not to use Swing for my application.
So I will ask another question. I still want transparent panels and labels but in AWT. I found code to make them transparent, but when I draw an image on the last panel (in the background), I have the trace of the panels and labels which are above, and their backgrounds have the same color than the panel on which I draw my image.
I DON'T UNDERSTAND !!!
I'm looking for a solution to have a background image in my labels, but I have the text or the background, never both, even using drawString instead of label constructor.
An idea ?
Excuse my English, I'm French. :0� -
SetOpaque(false);
Hello:
I have got your code on how to set a background image. Thank you so much.
But I have another question , my question is that
what is the purpose of the following method
setOpaque(false);
and also this method belongs to which class?DON'T CREATE A NEW THREAD EACH TIME YOU REPLY.
THE REPLY BUTTON IS LOCATED AT THE UPPER RIGHT CORNER.
REPLY TO THIS THREAD.
http://forum.java.sun.com/thread.jspa?threadID=5223082&tstart=0 -
Screen edges flickering after IOS 7 update?
I updated my iPhone 4S to the new IOS 7 and now the edges of my screen are flickering and faded. I downloaded a couple days ago and this just happened today.
I am using iPhone 4S GSM. after updating os to iOS7 the following issues are appeared.
1. Bottom of the screen is flickering some times during getting a call.
2. After screen flicker Siri is activated automatically.
3. Touchscreen is activating during a call(when I kept my phone near to my ear). this is triggering to activate speaker phone.
My OS version is 7.0.2 -
Iphone 6 plus screen edges colorization
Hello community
My ip6 plus has colorization around the edges of the screen in portrait mode. (As the phone is standing). It happens in all the apps I open.
If I don't open an app, i have a solid looking screen.
The colors I see are yellow, red, green, blue and just along the edges.
I am asking if anyone else is having this issue as my last iPhone 5 never had this.
Should I replace it with Apple.
Thank youHi there ankenymartialarts,
Welcome to Apple Support Communities.
The article linked below provides troubleshooting suggestions that can help you solve the discolored display issue with your iPhone 6 Plus.
Get help with the screen on your iPhone, iPad, or iPod touch - Apple Support
Ciao,
-Jason -
Green screen edges blend into background
I'm trying to use the green screen effect and I'm able to get everything to work however the foreground images are blending into the background images. There is no distinct edges between what is the foreground and the background.
Hi TCorpSoc,
According to your description, I do a test, in SQL Server 2008 SSMS or other versions, the colors in the panes or dialog boxes are a grey that is different from white. You can clear to recognize two colors. However, in SQL Server 2012 SSMS, they use whitish
grey and grey. It is indeed barely visible. In SSMS, there is not exist the user interface for customizing the environment colors of the panes or dialog boxes.
Although you can establish a custom font and color scheme for various user interface elements in Microsoft SQL Server Management Studio via the options about “Environment/Fonts and Colors Page”, it is not include the user interface elements
of panes or dialog. You can change font style, size, and color display settings for Text Editor, Printer, Find Results Window, Output Window, Execution Plan and so on. Note that color scheme changes do not take effect during the session in which you
make them. You can evaluate color changes by opening another instance of SQL Server Management Studio and producing the conditions under which you expect your changes to apply.
For more information about options (Environment/Fonts and Colors Page),you can review the following article.
http://technet.microsoft.com/en-us/library/ms189708.aspx
Regards,
Sofiya Li
If you have any feedback on our support, please click here.
Sofiya Li
TechNet Community Support -
IMac screen edges are showing light
Hello
i just bought my imac today and i noticed while watching movie when screen goes black the edges of screen shows white light.
is this a fault?I'm considering buying an iMac for the purpose of putting at the centre of a home cinema (amongst other things), and this was one of my questions too.
Have you thought of a physical low tech solution like draping a thick piece of cloth (maybe a bit of blackout curtain) over the iMac screen once you have the output going to the projector?
On a Window's box with dual displays, it is simple enough with most graphics drivers to output to only one screen or various other options. I'd have thought it was the same for a Mac. Hope someone else has a more informed answer. -
Halos in my iphone screen edges
I Have tow halos appear in the top of my iphone 5s screen in the edges (right and left)
i did buy from USA in Nov 2013 but i leave in Egypt
knowing that i'm using the original accessories with NO jallpreack
waiting your supportHi, Thanks Metalace.
I didn't put a magnet on it.
I turning it off, and i let fully drining the battery already.
I been seaching all aroud internet,... and i did not see a picture of an iphone with the same spots like mine.
-Something is wrong here.- (maybe an internal microchip, the screen, the sun)
Someone who forget his iphone under the sun found it 4 hours later with some kind of spots on the screen?
Many thanks -
Turning off switch spaces when hovering with a window near screen corner
Hi,
I use Spaces very often, but I absolutely hate that when you move a window near the corners of the screen and hold it there for about 1 second, that you switch spaces. I once found a terminal command which lets you set the delay the OS waits before switching spaces to 1 minute (so it it basically turned off). Now I can't find this site again. Does anyone know what I mean?This might still work:
http://www.macosxtips.co.uk/index_files/terminal-commands-for-hidden-settings-in -leopard.html
charlie -
Horizontal lines on screen edges macbook pro unibody 2008
I've suddenly got horizontal lines around the edges of my screen. I'm on a MBP late 2008 15". I have no idea what's causing it but it's definitely hardare related since they don't show up on a screen shot. Any help is greatly appreciated. Thanks.
You're just going to have to break down and take your machine to your local Apple Store or an AASP. It could be a GPU glitch, anything. Nothing odd about it not showing on a screenshot - you can only capture what's there on screen.
Go ahead and make that appointment with the Genius Bar folks...
Clinton
Maybe you are looking for
-
I downloaded the AE CC trial and erased it. Now I'm trying to download the application again and my computer doesn't let me because it reads I already have it. What can I do?
-
How to remove the silican ball from the audio jack
how to remove the silican ball from the audio jack in DV6 6116 laptop
-
Data import as a batch process - Issue on successive runs
Hi, We have a requirement of creating a batch process that will have to read data from REMOTE_TABLE on remote database system and insert all the rows into LOCAL_TABLE on our local data base. Scenario: When the batch runs for the first time, since LOC
-
Personal Web Sharing or equivalent?
I'm working on a server running Mac OS X Server version 10.4.5. I'm trying to set up personal web sharing, or whatever server equivalent there is, but I'm running into a major problem. Everything I've read tells me that I should be able to go to Syst
-
Problems downloading Photoshop 13 onto Mac, won't allow redemption code to ne typed
Please help. I have purchased Photoshop elements and premier elements 13 for my Mac. After downloading eventually (after a few failed attempts due to bad broadband signal) My Mac is asking of my redemption code ( long 6 box code on back of download c