java - JavaFx8 VBox center image -


i have javafx vbox inside of scrollpane:

vbox container = new vbox(); container.setalignment(pos.center);  ...  scrollpane.setcontent(container); scrollpane.setfittowidth(true); scrollpane.sethbarpolicy(scrollbarpolicy.never); scrollpane.setvbarpolicy(scrollbarpolicy.never); scrollpane.setminwidth(150); scrollpane.setpannable(true); 

the size of vbox never change, inside have labels, 1 label has user image next image(a)

the image resized height, don't know size of image, if width of image bigger width of vbox, happen(part of image hidden)(b)

but don't want this, want following image:(the sides of image hidden if image width bigger vbox width)(c)

http://i.stack.imgur.com/b3dok.png

how can this?

i tried put rectangle clip, in rectangle wanna show center of image, same happens.

imageview.setclip(new rectangle(centerx - recsize, centery - recsize, recsize*2, recsize*2)); 

---------------with clip----------------

red = original image

blue = part of image visible

http://i.stack.imgur.com/mybyf.png

nice(d)

not nice:(e)(labels not centered correctly because of image.)

sorry links, can't put images directly

solution

set viewport on image not clip.

imageview.setviewport(      new rectangle2d(500, 320, 420, 300) ); 

sample

here sample. it's not going match asking because linked images in question, can't quite understand trying do. think should give enough background info can learn accomplish want.

the sample creates image view graphic in scroll pane. image view applies viewport image , scales viewport preserved ratio. allows scaled portion of larger image displayed. it's kind of thumbnail clip (click on thumbnail display full image).

home

import javafx.application.application; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.effect.*; import javafx.scene.image.*; import javafx.scene.layout.vbox; import javafx.scene.paint.color; import javafx.scene.text.*; import javafx.stage.*;  // display captioned image in viewport. // click image expanded view. public class labelwithimage extends application {     private static final double image_width = 150;      @override     public void start(stage stage) {         image image = new image(image_loc);         imageview imageview = new imageview(                 image         );         imageview.setviewport(                 new rectangle2d(500, 320, 420, 300)         );         imageview.setfitwidth(image_width);         imageview.setpreserveratio(true);          label labeledimage = createcaptionedimage(                 imageview,                 "village home"         );          addglowonmouseover(labeledimage);         labeledimage.setonmouseclicked(event -> {             displayfullimage(stage, image);         });          vbox vbox = new vbox( // vbox there mimic question askers structure.                 labeledimage         );         vbox.setpadding(new insets(10));          scrollpane scrollpane = makescrollable(vbox);          scene scene = new scene(                 scrollpane         );          stage.setscene(scene);         stage.show();          stage.setmaxwidth(stage.getwidth());         stage.setmaxheight(stage.getheight());     }      private void displayfullimage(stage stage, image image) {         stage displaystage = new stage();          displaystage.initstyle(stagestyle.utility);         displaystage.initmodality(modality.application_modal);         displaystage.initowner(stage);         displaystage.setscene(                 new scene(                         new group(                                 new imageview(                                         image                                 )                         )                 )         );         displaystage.show();     }      private void addglowonmouseover(node node) {         glow glow = new glow();         dropshadow shadow = new dropshadow(20, color.gold);         glow.setinput(shadow);          node.setonmousepressed(event -> node.seteffect(null));         node.setonmouseentered(event -> node.seteffect(glow));         node.setonmouseexited(event -> node.seteffect(null));     }      private scrollpane makescrollable(node node) {         scrollpane scrollpane = new scrollpane(node);          scrollpane.sethbarpolicy(scrollpane.scrollbarpolicy.never);         scrollpane.setvbarpolicy(scrollpane.scrollbarpolicy.never);         scrollpane.setpannable(true);          return scrollpane;     }      private label createcaptionedimage(imageview imageview, string caption) {         label labeledimage = new label(caption);          labeledimage.setfont(font.font("athelas", fontposture.italic, 20));         labeledimage.setstyle("-fx-background-color: cornsilk");         labeledimage.setpadding(new insets(0, 0, 5, 0));         labeledimage.setgraphic(                 imageview         );         labeledimage.setcontentdisplay(contentdisplay.top);          return labeledimage;     }      public static void main(string[] args) {         launch(args);     }      private static final string image_loc =             "http://www.imgion.com/images/01/beautiful-village-home.jpg";             // image courtesy of http://www.imgion.com provides             // "free images on large topics share friends , on blogs." } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -