开发者

resizing a wrapped swing component in javafx

开发者 https://www.devze.com 2023-01-26 13:48 出处:网络
I read that you can resize (and transform in general) a wrapped swing component which can be obtained with SwingComponent.wrap(myComponent). I fail to see how. I see that the returned type开发者_如何学

I read that you can resize (and transform in general) a wrapped swing component which can be obtained with SwingComponent.wrap(myComponent). I fail to see how. I see that the returned type开发者_如何学运维 does inherit Resizable, but how do I set min/maxHeight, h/vfill and other properties?


This is not the best solution but it works. Below is sample code:


// Define the swing component, wrapper, and the scene.
var jPanel = new JPanel();
var swingWrapper = new SwingComponent.wrap(jPanel);
var scene = Scene{
     width: 700
     height: 500
     content: [
          swingWrapper
     ]
}

// Below are some triggers that fire off whenever the width or 
// height of the scene change.
var currentWidth = bind scene.width on replace{
    jPanel.setPreferredSize(new Dimension(scene.width, 
        scene.height));
    swingWrapper.width = scene.width;
}

var currentHeight = bind scene.height on replace{
    jPanel.setPreferredSize(new Dimension(scene.width, 
        scene.height));
    swingWrapper.height = scene.height;
}


Stage {
    title: "Some App"
    scene: scene
}


Below is an example of how you could set the properties you require:


def swingComponent : SwingComponent = SwingComponent.wrap(new JPanel());

 function setSwingComponentLayoutInfo():Void{
     swingComponent.layoutInfo = LayoutInfo{
         height: 200
         width: 200
         maxHeight: 400
         maxWidth: 400
         // ... other properties.
     }
 }

setSwingComponentLayoutInfo();

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消