当前位置: 首页 > 知识库问答 >
问题:

JPanel GridBagLayout到GridPane

充小云
2023-03-14
JPanel bottomMessagePanel = new JPanel();
bottomMessagePanel.setLayout(new GridBagLayout());
bottomMessagePanel.setBorder(BorderFactory.createEmptyBorder());
bottomMessagePanel.add(someJComponent, new GridBagConstraints(0, 0, 1, 1, .35, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
bottomMessagePanel.add(someOtherJComponent, new GridBagConstraints(1, 0, 1, 1, .65, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
JPanel stepPanel = new JPanel();
stepPanel.setLayout(new GridBagLayout());
stepPanel.add(someJComponent, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
stepPanel.add(someOtherJComponent, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
stepPanel.add(some3rdJComponent, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

任何帮助都是非常感谢的!

共有1个答案

文英达
2023-03-14

您可以指定GridBagConstraints,将值传递给构造函数。

GridBagConstraints(
        int gridx,
        int gridy,
        int gridwidth,
        int gridheight,
        double weightx,
        double weighty,
        int anchor,
        int fill,
        Insets insets,
        int ipadx,
        int ipady)

让我们描述一下如何在JavaFX中使用这些参数的等价物:

Node node = ...
GridPane gridPane = ...

通常使用适当的gridpaneadd方法来指定这些值。它们在JavaFX中称为columnindexrowindexcolumnspanrowspan。如果columnspanrowspan为1,则使用add方法取3个参数即可:

gridPane.add(node, gridx, gridy);
gridPane.add(node, gridx, gridy, gridwidth, gridheight);

您可以为此使用ColumnConstrants/RowConstraintsHalgening/code>/code>/code>属性,也可以使用GridPane.SetValignGridPane.SetValign:

GridPane.setHalignment(node, HPos.LEFT);
GridPane.setValignment(node, VPos.TOP);

与此等效的是设置行和列约束的fillheightfillwidth值,并使用gridpane.setfillheightgridpane.setfillheight:

GridPane.setFillWidth(node, Boolean.FALSE);
GridPane.setFillHeight(node, Boolean.FALSE);

这些属性的默认值为true

您可以使用gridpane.setmargin来指定。如果对所有值都使用0,则不需要指定此值。

GridPane.setMargin(node, new Insets(top, right, bottom, left));

在JavaFX中没有与此等价的东西。

 类似资料:
  • 我已经在我的游戏中实现了拖放功能,但到目前为止,我只能“拖放”到硬编码的位置。如图所示: 我想要的是: 当船舶被丢弃时,它的x、y值(相对于GridPane)被保存,或者 飞船掉落到的细胞被保存。 我的setOnDragDropped事件在此处处理: 我觉得这应该是一个简单的鼠标悬停事件或类似的事情,但我不知道该怎么做。 编辑:下面类的完整代码: }

  • 问题内容: 在PHP中,将RGB三元组转换为HSV值的最直接方法是什么? 问题答案:

  • 问题内容: 对于正在编写的程序,我正在使用base64.b64encode(f.read(image))从一台计算机上传输图像,并尝试在接收脚本中读取它而不将其保存到硬盘驱动器中(以最大程度地减少这种情况)处理时间)。我很难弄清楚如何将图像读取到OpenCV中而不将其保存在本地。 这是我发送图像的代码如下所示: 同时,这是接收它的代码。(这在on_message函数中,因为我正在使用MQTT进行传

  • 签到开关状态 获取签到信息 签到 累计签到排行榜 新版签到 签到开关状态 签到应用具有开关性质,管理员可从后台控制签到是否被开启或者关闭,而开关会在「启动信息」接口中提供。提供格式如下: { "checkin": true // Or "checkin": false } 签到金额格式: { "checkin:attach_balance": 0 } 金额为0时表示未配置 但是

  • 实时了解外勤人员位置活动轨迹及分布,出差也可以异地打卡。 开始你的第一次签到 如何签到 打开手机钉钉-工作-签到 签到按钮自动生成签到时间及签到地点 拍照自带时间和地点水印,提交完成签到 签到设置 根据公司要求选择签到相关设置 查看足迹 签到足迹 ● 点击右下角足迹,直观查看团队足迹,根据部门和日期筛选历史签到记录 ● 选择未签到,可以查看未签到人员,对未签到人员Ding一下 ● 点击足迹分布,可

  • 在上课页面的右下侧点击“活动-签到” 选择签到时间(一般为上课时间),点击"开启签到"。 页面跳转,实时显示目前签到人数,并可随时关闭签到。**