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

发布于 2024-10-03 02:01:15 字数 158 浏览 0 评论 0原文

我读到您可以调整(并且通常转换)包装的 swing 组件的大小,该组件可以通过 SwingComponent.wrap(myComponent) 获得。我不明白怎么做。我看到返回的类型确实继承了可调整大小,但是如何设置min/maxHeight、h/vfill等属性?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身骄傲 2024-10-10 02:01:15

这不是最好的解决方案,但它有效。下面是示例代码:


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

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
}

凉栀 2024-10-10 02:01:15

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


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

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

setSwingComponentLayoutInfo();

希望有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文