Dynamically resize jframe/image or scroll(动态调整 jframe/图像或滚动)
问题描述
如本问题所述(将图像包装到 Jframe),我需要一个 jframe 来匹配提供的确切图像(图像本身是一个已转换为图像的 PDF)
提供的解决方案确实为我的图像尺寸构建了一个 jframe,但我实际上无法看到所有图像.我需要能够调整 jframe 的大小,使图像动态调整为新的 jframe 大小.如果做不到这一点,我想如果我可以滚动 jframe 甚至放大或缩小,我至少可以到达我目前看不到的图像部分.
我需要这个的原因是,在我的代码中,我可以选择根据图像绘制一个 Rectangle2D - 代码将坐标吐出为 java.awt.geom.Rectangle2D$Float[x,y,w,h].
然后,我将使用 Apache PDFbox 中的 PDFTextStripperbyArea 类使用这些坐标针对原始 PDF 提取区域.PDFTextStripperbyArea 将其输入作为 Rectangle2D 测量值.因此,图像和 jframe 的大小必须始终相同才能检索到准确的坐标.
有人可以帮忙吗?
要使用滚动窗格扭曲标签,您可以实现以下更改:
//frame.setLayout(new FlowLayout());- 注释掉 - 使用默认值(Borderlayout)JLabel lbl=新的 JLabel();lbl.setIcon(图标);JScrollPane jsp = new JScrollPane(lbl);//用滚动面板扭曲标签//frame.add(lbl);框架.add(jsp);//将滚动窗格添加到框架而不是lbl
您可以在这里找到更多信息..p>
As discussed in this question (Wrap image to Jframe), i need a jframe to match the exact provided image (The image itself is originally a PDF which has been converted to an image)
The solution provided does indeed build a jframe to my image dimensions, but i can't actually see all of the image. I need to be able to resize the jframe, with the image dynamically adjusting to the new jframe size. Failing that, i think if i could just scroll the jframe or even zoom in or out, i could at least get to the parts of the image that i currently cannot see.
The reason i need this is that, within my code, i have an option to draw a Rectangle2D against the image - the code spits out the co-ordinates as java.awt.geom.Rectangle2D$Float[x,y,w,h].
I will then use these co-ordinates to extract the region against the original PDF using PDFTextStripperbyArea class from Apache PDFbox. PDFTextStripperbyArea takes its input as Rectangle2D measurements. Hence, the image and the jframe must always be the same size in order to retrieve accurate co-ordinates.
Can anybody help?
To warp the label with a scroll pane you could implement the following changes:
//frame.setLayout(new FlowLayout()); - comment out - use default (Borderlayout)
JLabel lbl= new JLabel();
lbl.setIcon(icon);
JScrollPane jsp = new JScrollPane(lbl); //warp the label with a scrollpane
//frame.add(lbl);
frame.add(jsp); //add scrollpane to frame instead of lbl
You can find more information here.
这篇关于动态调整 jframe/图像或滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:动态调整 jframe/图像或滚动
基础教程推荐
- 在螺旋中写一个字符串 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01