I have a Swing application with standard size and I would like to refactor all the components, which takes long time. I used AffineTransform
with JXlayer
. I'm able to view the resized components but not able to get and print the new resized dimensions. How can I achieve this?
Asked
Active
Viewed 75 times
0

stefanobaghino
- 11,253
- 4
- 35
- 63

m vineela
- 23
- 2
-
The question that begs to be asked is, why aren't you making better use of one or more layout managers – MadProgrammer Jan 05 '18 at 07:30
-
Thanks for the suggest but my application as developed very long back ago. and as large code to change to layout managers. I tried with your solution : https://stackoverflow.com/questions/21174997/how-to-add-mouselistener-to-item-on-java-swing-canvas . And quite happy with result . But in that I would like to have the resized components dimensions of a component. where I am Printing the logs it showing the old dimensions but displaying resized component. Can u help me out. – m vineela Jan 05 '18 at 08:35
-
Not really, as the components are actually resized, it's just that when they are painted, the `Graphics` context has been scaled. The best you can do is take the current size/position and manually apply the scaling factor to them – MadProgrammer Jan 05 '18 at 08:56
-
public void manualScaling(Component Comp){ int w = (int) Comp.getWidth(); int h = (int) Comp.getHeight(); BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics gtest = bi.getGraphics(); gtest.drawImage(bi, 0, 0, null); float[] scales = { 1.5f }; float[] offsets = new float[4]; RescaleOp rop = new RescaleOp(scales, offsets, null); Graphics2D g2test = (Graphics2D) gtest; g2test.drawImage(bi, rop, 0, 0); System.out.println(bi.getHeight()+"-" + bi.getWidth()); } – m vineela Jan 12 '18 at 06:34
-
Hi @MadProgrammer From the above I wrote a method to scale a jComponent manually from graphic 2d I am drawing the image and printing the dimensions but again getting the same old dimensions . I didnt get where I went wrong.... – m vineela Jan 12 '18 at 06:37
-
The physical dimensions of the components don't/won't change, because you're not scaling the components, you simply scaling how they are rendered – MadProgrammer Jan 12 '18 at 06:46
-
@MadProgrammer ok I understand , My target is that with the new scaling dimensions I need to calculate the remaining space that I have in the frame and I need to Increase the other components with in that space. Is that possible ? :( – m vineela Jan 12 '18 at 06:52
-
Hi @MadProgrammer . With your solution https://stackoverflow.com/questions/21174997/how-to-add-mouselistener-to-item-on-java-swing-canvas. I converted JXlayer to Jlayer in the Code. But In that I am unable to setLayer(LayoutManger mgr) through JLayer(not supported) as it is override from container. Previously you are doing with Container SetLayout(LayoutManganer mgr). . Is it possible to set the Layourmanager object from JLayer? – m vineela Jan 29 '18 at 12:38
-
I’ve not had the time to explore JLayer so i can’t say – MadProgrammer Jan 30 '18 at 21:40