在javafx中调整包装的swing组件
问题描述:
我读过,您可以调整大小(并通常转换)可以使用SwingComponent.wrap(myComponent)获取的包装swing组件。我看不出如何。我看到返回的类型确实继承了Resizable,但是如何设置min/maxHeight,h/vfill和其他属性?在javafx中调整包装的swing组件
答
这不是最好的解决方案,但它的工作原理。下面是示例代码:
// 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
}
答
下面是如何,你可以设置你需要的属性的例子:
def swingComponent : SwingComponent = SwingComponent.wrap(new JPanel());
function setSwingComponentLayoutInfo():Void{
swingComponent.layoutInfo = LayoutInfo{
height: 200
width: 200
maxHeight: 400
maxWidth: 400
// ... other properties.
}
}
setSwingComponentLayoutInfo();
希望有所帮助。