在javafx中调整包裹的swing组件的大小

时间:2010-11-19 19:43:08

标签: swing javafx

我读到你可以调整(并且通常转换)一个包裹的swing组件,它可以用SwingComponent.wrap(myComponent)获得。我没看到怎么样。我看到返回的类型确实继承了 Resizable ,但是如何设置min / maxHeight,h / vfill和其他属性?

2 个答案:

答案 0 :(得分:0)

这不是最佳解决方案,但可行。以下是示例代码:


// 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
}

答案 1 :(得分:0)

以下是如何设置所需属性的示例:


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

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

setSwingComponentLayoutInfo();

希望有所帮助。

相关问题