动态调整 jframe/图像或滚动

Dynamically resize jframe/image or scroll(动态调整 jframe/图像或滚动)

本文介绍了动态调整 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/图像或滚动

基础教程推荐