JavaFX 8 - way reasonable to make a canvas to fill its parent

This here is the essence of a problem with a canvas that I have right now

public class Test extends the Application

{

Public Shared Sub main (String [] args)

{

Launch (args);

}

@Override

public void start (point primaryStage)

{

TabPane tabPane = new TabPane();

Tab = new Tab ("Tab");

tabPane.getTabs () .add (tab);

BorderPane borderPane = new BorderPane();

tab.setContent (borderPane);

Canvas MyCanvas = new MyCanvas();

borderPane.setCenter (canvas);

canvas.setWidth (500);

canvas.heightProperty () .bind (borderPane.heightProperty ());

Scene = new scene (tabPane, 1300, 800);

primaryStage.setScene (scene);

primaryStage.show ();

}

MyCanvas class extends Canvas

{

public MyCanvas()

{

this.widthProperty () .addListener (evt-> draw());

this.heightProperty () .addListener (evt-> draw());

}

private void draw()

{

Double width = getWidth();

double height = getHeight();

System.out.println (width + ";" + height);

Context GraphicsContext = getGraphicsContext2D();

context.clearRect (0, 0, width, height);

context.setFill (Color.GREENYELLOW);

context.fillRect (0, 0, width, height);

}

}

}

The interesting line is

canvas.heightProperty () .bind (borderPane.heightProperty ());

This works only at halfway, when the window expands the draw functions, that all are called, but when the window is more tiny draw function is not called.

Now, I thought that maybe I should go higher up in the hierarchy.

canvas.heightProperty () .bind (tab.?   tab has no heightProperty

A more?

canvas.heightProperty.bind (tabPane.tabPane.heightProperty ());

Now this seems good (it works when it gets bigger or smaller), until you realize that it will be always at least 29 big pixels (at least on my system)

test.png

The reason is that the header is the pixel 29 missing. But I don't see a way to get the size of the header of the tabPane. Now, I could just subtract the tabPane.heightProperty 29, but it won't work that on my system, it might be a different size on other systems or javafx could change.

I looked at a few other ways to get a resizable canvas, but things like the creation of a custom component and only put the canvas substituting the layoutChildren method seems more like a hack of a proposed solution.

I would really appreciate a way to resize my paintings on request, without going any further than the parent of my canvas (borderPane in my case).

You can use something like this to make a resizable canvas.

public final class CanvasPane extends Region {

    private final Canvas delegated = new Canvas();

    public CanvasPane() {
        getChildren().add(delegated);
        delegated.widthProperty().addListener(observable -> draw());
        delegated.heightProperty().addListener(observable -> draw());
    }

    @Override
    protected void layoutChildren() {
        super.layoutChildren();
        final double width = getWidth();
        final double height = getHeight();
        final Insets insets = getInsets();
        final double contentX = insets.getLeft();
        final double contentY = insets.getTop();
        final double contentWith = Math.max(0, width - (insets.getLeft() + insets.getRight()));
        final double contentHeight = Math.max(0, height - (insets.getTop() + insets.getBottom()));
        delegated.relocate(contentX, contentY);
        delegated.setWidth(contentWith);
        delegated.setHeight(contentHeight);
    }

    private void draw() {
        final double width = delegated.getWidth();
        final double height = delegated.getHeight();
        final GraphicsContext gc = delegated.getGraphicsContext2D();
        gc.setFill(Color.GREENYELLOW);
        gc.fillRect(0, 0, width, height);
    }
}

Also, it is really unnecessary to link anything because you set this control within a BorderPane: it is automatically resized to the dimensions of the central area.

You can create a similar class for a resizable ImageView.

Tags: Java

Similar Questions

  • How to make transparent canvas

    How to make transparent canvas

    Open the layer panel.

    Click on the lock symbol where it says background

    Select all (CMD - A or CTRL)

    Press the delete key

  • How make the USB auto-ouvrir its Nav Pane folder when I plug. Vista for this? __

    In the Navigation pane (what I call the directory root - no?), when I plug a USB key, I have to click on the folder "Computer" to open it, then the folder of USB stick to open that in order to be able to drag files from the hard drive to the files inside. The bookmarks bar is useless, it's just a subfolder in the "Favourites", just as boring the USB folder and is not yet open USB folder in the Nav pane. I can't find a way to make the USB auto-ouvrir its Nav Pane folder when I plug. Vista can do this?

    This is a Windows update that addresses the functionality of Autorun.  I don't know if it can solve your problem, but it can facilitate some of the following solutions or allow them to work if Vista is up to data: http://support.microsoft.com/kb/971029.

    Here's how to use Autorun with a USB Flash drive that can solve your problem (but it is a bit Advanced): http://www.samlogic.net/articles/autorun-usb-flash-drive.htm.

    Here is a free download which probably fix the AutoPlay in Vista and XP (when I insert my flash drive, a menu popss send me the optios including by studying the disk and when you click it it starts at the root of the drive, and I think that should happen with your USB key as well). http://www.mydigitallife.info/2008/01/15/cleanhandlers-free-download-autoplay-cleanup-utility-for-xp-and-vista/.  I don't know if this will help, but it may solve the problem.

    Here is another article with a procedure of activation autorum for USB drives.  I think you want to insert explorer.exe as filename to open Windows Explorer. http://www.pctipsbox.com/how-to-autorun-programs-from-usb-flash-drive/.

    Here's yet another article on how to set up automatic execution for a USB key: http://www.dailycupoftech.com/usb-drive-autoruninf-tweaking/.

    I hope that one or more of these items helps solve your problem and allow you to do what you want to do with the USB.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • How to make a vector transparent while its edges not?

    I want to reproduce the following image (representing a face):

    hMrnWPf.png

    Using this vector:

    mlFQE8w.png

    That you can download here.

    I want to make this transparent vector while its edges should not be. How can I do? I'd appreciate the help.


    Thank you very much
    Cesare

    Cesare,

    If I (put) understand, you can:

    (1) (select the paths forming the shape of the face and Ctrl / Cmd + C + X + C to create a copy on the front very, if more of a Pathfinder > unite for one way;)

    (2) in the tool box, value None Fill and Stroke and assigned to the desired weight and color (Cap/Join).

    You can move it to a new layer, or hide/remove the original, so that you can save and export the new path by itself.

  • Error 1430 to copy in Untitled 1. Possible reasons: LabVIEW: the path is empty or a parent. You must use an absolute path.

    I wrote a code to copy a file to a folder IE C:\Folder1:\Hello.txt to another folder C:\Folder2. But it shows an error in the copy. Is to show that 1430 error to copy in Untitled 1. Possible reasons: LabVIEW: the path is empty or a parent. You must use an absolute path.  Can someone help me please how to fix this problem. I've also attached the VI. Thanking you.

    Hello

    Change while loop to loop For!

    Kind regards

  • In CC Dramweaver Adobe how to make my Web page fill the entire window?

    In Adobe Dreamweaver CC how to make my Web page fill the entire window?

    A width of 100% CSS.


    Body {width: 100 %}}

    Nancy O.

  • My companies site only appears correctly in Internet Explorer compatibility view. Is there a way I can make it work properly in FireFox?

    My small company uses JustHost to host our Web site.

    Recently, I went to Firefox of Internet Explorer and found that the site is not displayed correctly. I looked back on Internet Explorer and found it was only display correctly on that because of the compatibility view.

    I looked in the admin section of the site for a way to solve this problem, but I can't find anything. It is a problem, because it means that all potential customer consults our site without Internet Explorer won't be able to see properly.

    Is it possible to update the site, so it can be displayed correctly in Firefox?

    "Compatibility view" is a crutch for IE users, since the days when Microsoft thought they controlled the internet and had their own 'standards '.

    You have some Fixin ' to do. All it may take is a tweak of the main CSS file, but it will take more than that.

    That's what the W3Org validator service says:

    http://validator.w3.org/check?URI=http :// www.turnbullfiresafety.com/

    Try announcement Web development / standards evangelism MozillaZine forum. The helpers there are better informed on the problems of development of web page with Firefox.

    http://forums.mozillazine.org/viewforum.php?f=25

    You will need to register and log in to post in this forum.

  • Is there a way to Movie Maker to record a tutorial on screen?

    I would like to show steps if need to video record the full screen while using the mouse to click through the steps and record my voice at the same time.

    Is there a program built into Windows 7 that will do it?

    If not, does anyone have a recommendation?

    I looked through the forums and have not found anything similar.

    Thank you.

    Hello

    Thanks for posting your question in the Microsoft Community forums.

    I see from the description of the problem, you want to know if there is a program in Windows 7 that can record video the steps and the sound at the same time.

    I will surely you help with this.

    In Windows Movie Maker there is no option to record the sound and the steps. You can use the action recorder to automatically capture the steps you take on a computer.

    But there is no audio recorder in the action recorder. You can add comments wherever you need to add a description.

    Check out the link for more information.

    Looking for a program that supports these features, you can use your favorite search engine.

    Important: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

    Hope this information helps you. If you need additional help or information on Windows, I'll be happy to help you. We, at tender Microsoft to excellence.
  • Where is the HTML5 Canvas publish setting "make sensitive > scale to fill the visible area"?

    I'm trying to publish my flash converted to project canvas HTML5. I'm used to be able to scale the output in the browser dynamically. Looking at the available documentation and online help, that I can see that there is a setting that seems to be what I'm looking for.

    Documents to create HTML5 Canvas to animate CC

    But the screenshot of the creation of the publication is not what I have on the screen, the whole Middle section is missing.

    https://helpx.Adobe.com/animate/using/creating-publishing-HTML5-canvas-document/_jcr_conte nt/main-pars/image_376055745.i...

    using animate pro 2015.2?

    If Yes, attach a screenshot of what you see in the publication settings.

    If this isn't the case, please update.

  • How to make a canvas scalable HTML5 document?

    Don't get me wrong! I'm not asking how you can scale the project! Nor am I asking how can I do a responsive project!

    The issue is subject after the project is exported and seen how content designed on a scale with the browser window.

    It is also something pretty easy to do on board animate. You could just flip through the button beside where it says px % for size options and position.

    Even with captivate you can export html scalable code. Yet once I speak not a sensitive project. I want to talk about evolving html that resizes with the display window.

    How is it that something as basic as that is not included by default?

    Is it perhaps a code snippet, Miss me that I could drag it to the first frame of my calendar to make the scene and scalable content?

    There are already a few threads on this:

    A scale of Composition Html how to adapt the browser?

    How can I make the output size of "Web" animate CC to adapt in an HTML page?

  • Find a way to make the IR to fill a full page width and not a part of it?

    Hello

    I have an interactive report in a page, but I want it to fill the width of the entire page. Currently, it only fills a part if it.

    Is there a way to do this?

    Here is a screenshot to show the current situation:

    Example of current situation

    I want the IR, IE create a button to raise vertically logout, IE use the full width available on the screen.

    Oracle database: 11.2.0.3.0

    APEX: 4.2.4.00.08

    With the help of theme: 25 reactive blue

    TIA,

    Dionisis

    Dionisis,

    Found this thread https://community.oracle.com/thread/1095348?tstart=0

    Apply his solution to this demo application, and it seems to work

    https://Apex.Oracle.com/pls/Apex/f?p=36281:1

    Jeff

  • Is there a way I can make you so when someone is filled out a form to fill live they can't send it until all the fields are filled?

    I have a PDF document that is a form with a submit button. However, I'm not sure if I can do fill in all mandatory fields until they can push send. Does anyone know how to do this?

    Thanks in advance

    Hi strictlys32285696,

    Inform that you can set the fields as required so that the user cannot submit the form without having to fill in all fields (an error message will appear & empty required field is highlighted)

    Please refer to this article as well (key word: 'General tab of the properties of form field'):- PDF, Adobe Acrobat form field properties

    Kind regards

    Christian

  • Can you make a model of filling to the Center?

    Hello world

    I was wondering if anyone knew if there was a way to change model of bucket fill parameters so that the model starts from the Center and fills with outside? Whenever I use the model always fill his stats from the upper left corner, which often means the repetition does not look quite symmetrical depending on the size of my canvas. It's a bit of pain resizing and the reorganization of the presentation of my models, so I was wondering if there was an easier way to do this?

    Thanks for the answers in advance.

    Hi, you need to make a new fill layer:

    1. in the main menu, choose layer/new layer fill / Pattern

    2. in the layer window, choose a name for your layer and click OK

    3. in the filling of model window, choose the right model in the preset menu, to move your model, you just drag & drop the mouse directly on your window of woking.

    Once you make your new fill layer, you can change the settings in the layer panel. Just double click on the thumbnail and you will access the model to fill window again.

  • Is there a way to get the list of hosts and its groups of belonging to the vCenter folder level in 5.5 web vsphere client plugin development?

    Hello

    I need to get the list of all hosts and its groups of belonging to the vcenter folder level.

    1. I created a view giving the extension point: vsphere.core.folder.monitorViews.

    2. After this step, I wrote the constraint as in my class of mediator,

    var ListConstraint:Constraint =

    QuerySpecUtil.createConstraintForRelationship ( _contextObject, 'childEntity');

    I was expecting a list of all child entities such as hosts, dc, cluster... But I have only the immediate child object which is only the Datacenter as my result.

    Is it possible to get all hosts and vCenter folder level Clusters because I need the entire list to vCenter (highest level).

    Other info:

    Object file has only two properties:

    1 childEntity - list of entities

    2 childType in-kind folder ('Virtual Machine', 'Data center'...)

    Is it possible to write a constraint specifying which list of childEntities I need using childType in.

    Example: Make Me childEntities that has a 'Host' and 'Cluster' childType but childType in doesn't have these two types.

    In addition, at this level, I could see the 'Associated objects' tab which has all the information I need, such as Clusters and Cluster tab hosts and host tab respectively.

    So, I think its possible to get this list to vCenter folder level.

    I have attached a screenshot representing the need. Kindly ignore the Conventions of naming in there since I edited the example comes with the sdk program.


    Query:

    1. How can I get the host and Cluster (table of relationship) list to vCenter folder level or even at the level of the vise.global.view?

    2. once I get this list, is it possible for me to manipulate that list and send the new list to IU?

    3. is there another way to do the same thing without the help of model classes and mediator?


    Pointers to this will be very useful.

    It is not possible to obtain all hosts a folder specific vCenter from a single query Data Manager.  You need to get the list of centers of data first and then get a list of data center hosts.

    It is best to make these repeated requests to the java level and return only the list that you want to the user interface.

    You can get all the objects in the host of the system with a simple query using a constraint with targetType = 'HostSystem', but you will need to eliminate those from other vCenter servers.  See how this chassis example queries all hosts the Java later in the getHosts() method: samples/chassis-app/chassisRackVSphere-service/src/main/java/com/vmware/samples/chassisRackVSphere/ChassisRackVSphereDataAdapter.java

    Another option is to use the vSphere Web Services SDK to browse vCenter. See the vSphere management forum for help on these APIs.  See this plugin of the sample using this SDK

    samples/vsphereviews/vsphere-wssdk-provider/src/main/java/com/vmware/samples/wssdkprovider/VmDataProviderImpl.java

  • Quick way to create a gradient of selected fill color?

    I create gradients all the time and I wonder if there is a quick way to create a gradient based on the fill color of the currently selected object. For example: I chose an area with a BLUE fill color. I'm going in the gradient panel and see that what the gradient will be if I click on it (which is usually based on a default gradient WHITE to BLACK, or it comes from the most recent gradiented object, I've touched). So I click on it and the gradient is enabled with the stops not being is not BLUE. What I want is... If I select a box with a BLUE fill and click on gradient - it will create a gradient with the two cases being the same BLUE as the fill color. It would be very convenient because instead of clicking on each stop, shift-eyedropping the blue color in an area of duplicated, it would begin immediately with the gradient of blue-blue for me to adjust (in the case below for a button I'd the superior light and lower darker stop).

    Screen Shot 2012-12-14 at 5.04.17 PM.png

    It is rather useful to select an object with a gradient to 'copy' this gradient, select a new object, click the gradient panel and have this new object to take on this exact gradient. But most of the time I'm not degraded copy but I'm creating new ones, and it makes more sense for me to create a gradient fill color. It would be helpful to someone else?

    This script is that it creates a gradient with both having the same color as the selected object

    var idoc = app.activeDocument;
    var sel = idoc.selection[0];
    
    var myGrad = idoc.gradients.add();
    myGrad.gradientStops[0].color = sel.fillColor;
    myGrad.gradientStops[1].color = sel.fillColor;
    
    var fillcolor = new GradientColor;
    fillcolor.gradient = myGrad;
    sel.fillColor = fillcolor;
    

Maybe you are looking for