jlayeredpane

How to rotate a buffered image without cropping it? Is there any way to rotate a JLayeredPane or JLabel?

折月煮酒 提交于 2019-12-06 13:21:33
I had searched about it but I did not get straight forward answer. I want a buffered image to be rotated but not cropped I knew the new dimensions are gonna be some thing like this int w = originalImage.getWidth(); int h = originalImage.getHeight(); double toRad = Math.toRadians(degree); int hPrime = (int) (w * Math.abs(Math.sin(toRad)) + h * Math.abs(Math.cos(toRad))); int wPrime = (int) (h * Math.abs(Math.sin(toRad)) + w * Math.abs(Math.cos(toRad))); Provide me a method for that. BTW is there any way to rotate a JLabel with an ImageIcon ? Intention: adding to panels and layered pane and also

Java Swing: Clearing custom painting from a JPanel overlayed with other JPanels in a JLayeredPane

谁说胖子不能爱 提交于 2019-12-06 08:54:10
I've got a JLayeredPane containing three JPanels, two of which overlap, that I'm painting shapes to. One of the two JPanels that overlap needs to have every shape drawn to it cleared without affecting the shapes drawn to the JPanel under it disappear from the screen. Currently I'm using something like this: Graphics g = pane2.getGraphics(); g.clearRect (0, 0, 1000, 1000); But this not only clears everything painted to pane2 but also pane1, which is under it. So my question is: Is there any way to clear everything painted to one JPanel without affecting anything painted to a JPanel under it? I

JMenuItems painting over higher components in JLayeredPane

筅森魡賤 提交于 2019-12-06 08:01:09
问题 I have a set of JMenuItems in a JPanel on one layer of a JLayeredPane, and an emulated cursor painted in a JPanel on a higher layer. When the menu items repaint, they paint over the emulated cursor (without triggering a repaint of the cursor layer). Interestingly, if I substitute JButtons or JLabels for the menu items, the cursor is correctly painted each time the menu items repaint. How can I ensure that repainting the menu items will cause the affected regions of the higher layers to

Graphics not showing in JLayeredPane (java swing)

北城余情 提交于 2019-12-06 01:48:15
问题 I'm trying to gradually build up an image based on user inputs. What I'm trying to do is create a bunch of graphics and add them as layers however I'm having some issues as they won't show up. Here is the code I'm using: public class ClassA { protected final static int dimesionsY = 1000; private static int dimesionsX; private static JFrame window; private static JLayeredPane layeredPane; public void init() { window = new JFrame("Foo"); dimesionsX = // some user input window.setPreferredSize

Using GridBagLayout in a JLayeredPane

橙三吉。 提交于 2019-12-05 02:07:46
问题 I am attempting to have a small floating "widget" of sorts in the top right of a JPanel. It's a fixed-size component - think of the compass in a google maps sort of view, if that helps. I realize that JLayeredPane only uses one layout manager for all the layers and so thought that using GBL with be successful: - make the top right (1, 0) box very small and put the widget there - make the content panel be of width/height 2 But after experimenting, it seems that GBL removes some components when

adding JLayeredPane to JPanel

主宰稳场 提交于 2019-12-04 18:52:58
问题 I am trying to add a JLayeredPane to a JPanel and then add an image (JLabel icon) and a button to the JLayeredPane, but neither show up. I've tested the image without the button and the layeredpane so I know that works. Here is some of the code I am using. Is there something I am missing or doing wrong? public class MyClass extends JPanel { private JLayeredPane layeredPane; private JLabel imageContainer = new JLabel(); private JButton info = new JButton("i"); MyClass(ImageIcon image) { super(

JMenuItems painting over higher components in JLayeredPane

醉酒当歌 提交于 2019-12-04 11:59:47
I have a set of JMenuItems in a JPanel on one layer of a JLayeredPane, and an emulated cursor painted in a JPanel on a higher layer. When the menu items repaint, they paint over the emulated cursor (without triggering a repaint of the cursor layer). Interestingly, if I substitute JButtons or JLabels for the menu items, the cursor is correctly painted each time the menu items repaint. How can I ensure that repainting the menu items will cause the affected regions of the higher layers to repaint as well, without directly calling repaint() on the layered pane? The situation I've described is

JLabel and JLayeredPane - How to display an image over another image?

泄露秘密 提交于 2019-12-03 17:04:17
I try to create a little game in java but I'm in trouble. When I draw a map, I'm not able to display the characters without overwrite the titlesets of the squares. My goal is to be able to display many pictures on the same square (like the titleset of the grass, the character and a tree), so I have to deal with the transparency of my pictures (this is not the problem) and the layer (it is the problem). So how can I display an image on another image? How can I explain to java that I need to display this image on or under another image? This is my source code. I don't know is that can help you.

Making JButtons overlap

假如想象 提交于 2019-12-03 15:15:04
I'm creating a virtual piano type program in Java Swing. My area for the piano keys right now is a JPanel with a horizontal BoxLayout containing white JButtons as white keys. I want to add black keys as well, and have them overlap the white keys. There are two different approaches I've tried. One is using the OverlayLayout. Unfortunately there isn't much documentation online for the OverlayLayout manager, and it's not available in the NetBeans GUI builder. I don't have a clue how to make it work. The second thing I've tried is using JLayeredPanes. I can't seem to figure that one out either,

adding JLayeredPane to JPanel

南楼画角 提交于 2019-12-03 12:32:13
I am trying to add a JLayeredPane to a JPanel and then add an image (JLabel icon) and a button to the JLayeredPane, but neither show up. I've tested the image without the button and the layeredpane so I know that works. Here is some of the code I am using. Is there something I am missing or doing wrong? public class MyClass extends JPanel { private JLayeredPane layeredPane; private JLabel imageContainer = new JLabel(); private JButton info = new JButton("i"); MyClass(ImageIcon image) { super(); this.imageContainer.setIcon(image); this.layeredPane = new JLayeredPane(); layeredPane