Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
766 views
in Technique[技术] by (71.8m points)

java - Dynamically resize jframe/image or scroll

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...