I have a JEditorPane in a JPanel. I want to know how far from the left and the right the JEditorPane is from the edge of the JPanel (or the frame as they are the same).
Is there a way to do this?
The Reason Is: I want to put a gradient on the JEditorPane that aligns to the edge of the JPanel in stead of the JEditorPane. The reason I want to do this is because there is a gradient on the JPanel and I don't want the JEditorPane background to appear to cover up the gradient. I would set the background to transparent but I got screen paint issues that I was unable to resolve.
Just call getLocation on your JEditorPane. The location of a Component is relative to its parent.
Related
Is there any way that i can add a jlabel on top of the canvas? In my code, the constructor of my frame adds the label first before adding the canvas but when i run it it does not show the label.
I am painting the background of my canvas.
Suggestions:
Don't use Canvas objects. You've got a Swing GUI and should use the Swing equivalent -- a JPanel.
Draw the background image in the JPanel's paintComponent method as the tutorials and hundreds of examples on this site will show you.
Add the JLabel to the JPanel not to the JFrame.
Then add the JPanel to the JFrame.
Layout managers and your understanding of them are critical. Understand that a JPanel uses FlowLayout by default, and if you add a single JLabel to it, it will be placed in the center top region of the JPanel. Requisite Layout Manager Tutorial Link
I've made a JFrame with the next Properties:
setLayout(null)
setUndecorated(true)
setResizable(false)
within i've put a JLabel with one Icon(PNG image) in netbeans, and im looking for some soluction that disable the backgroud(full Transparent, and unactive) when the mouse moves THROUGH JFrame's Image(or someother component) BUT the mouse works different outside of the JLabel because JLabel Icon avoid any mouse action over the JLabel. But there's a default Gray background that doesnt exactly what i want.
We can see that mouse doesnt do anything on the JLabel(unless there were some component in the Frame)
Green = JFrame size.
And here the mouse change when moves through of the web page
im looking for some soluction that disable the backgroud(full Transparent, and unactive) when the mouse moves
Don't use full transparency.
If the pixels are not 100% transparent, then the MouseEvents will be handled by the frame.
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 want to create java applet having Canvas or Panel. Now when i start entering data using drawstring(), height of Canvas or Panel should increase dynamically and scroll bar should be visible.
How can I implement such applet?
Please let me know even this can be achieved by using control other then Canvas or Panel.
Thank you in advance.
Use Swing. Why paint the text when a JTextArea or JEditorPane can paint it easily?
Drop the JTextComponent into a JScrollPane, put that in a JPanel, add the JPanel to a JApplet. Job done.
I set the background of a JWindow completely transparent. Then I painted a rounded Rectangle (RGB: 0,0,0,100) in it's paint-Method and added a JLabel to the JWindows ContentPane. But when I try to repaint the JWindow to update the JLabel, it doesn't remove the old Rectangle and the old value of the JLabel. So the result is that my custom tooltip box (what it should be) gets less transparent and you cannot read the JLabels contents, because it overlays the old contens.
Is there any way to solve this problem?
BTW, if I don't repaint, it doesn't get less transparent, but the new contents of my JLabel overlays the old Contents, like it is, when I repaint.
First you should override paintComponent instead of paint and call super.paintComponent(g). You should leave JWindow opaque, because the component on the rearmost layer will clear the old contents. If all the layers are transparent you will end up with screen garbage.
See painting with Swing. Perhaps you really wanted to create translucent windows?