【问题标题】:Netbeans Platform LayoutNetbeans 平台布局
【发布时间】:2012-05-07 20:28:20
【问题描述】:

我已经使用 netbeans 平台设计了一个小应用程序,现在我想更改 netbeans 平台提供的基本布局的方向。我有一个显示如下所示的窗口

我希望在启动时显示如下屏幕。我已经调整了大小以满足我的需要,但我希望它自己发生。

经过激烈的谷歌搜索,我发现我需要在其中一个模块中创建一个layer.xml 并将以下代码添加到其中。

<folder name="Windows2"> <file name="WindowManager.wswmgr" url="WindowManager.wswmgr"/> </folder>

我的WindowManager.wswmgr 文件如下所示

<windowmanager version="2.1">
<main-window> 
    <joined-properties centered-horizontally="true" centered-vertically="true"
                       width="630" height="400" />
    <separated-properties centered-horizontally="true" relative-y="0.1"
                       relative-width="0.6" relative-height="0.08" />
</main-window>
<editor-area state="joined">
    <constraints>
        <path orientation="horizontal" number="60" weight="0.5" />
        <path orientation="vertical" number="40" weight="0.7" /> 
        <path orientation="horizontal" number="40" weight="0.5" /> 
    </constraints>
    <relative-bounds x="33" y="24" width="42" height="44"/>
</editor-area>
<screen width="1024" height="800" />
<active-mode name="explorer" />
<maximized-mode name="" />
<toolbar configuration="Standard" preferred-icon-size="24" />

我现在该怎么办?我错过了一些明显的东西吗??

--编辑--

layer.xml

<filesystem>
<folder name="Actions">
    <folder name="Window">
        <file name="org-choose-transaction-ChooseTransactionTopComponent.instance_hidden"/>
        <file name="org-choose-transaction-EnterAmountTopComponent.instance">
            <attr name="instanceCreate" methodvalue="org.openide.windows.TopComponent.openAction"/>
            <attr name="preferredID" stringvalue="ChooseTransactionTopComponent"/>
        </file>
        <file name="org-prowze-maketransaction-TransactionTopComponent.instance">
            <attr name="instanceCreate" methodvalue="org.openide.windows.TopComponent.openAction"/>
            <attr name="preferredID" stringvalue="transactionTopComponent"/>
        </file>
        <file name="org-prowze-maketransaction-transactionTopComponent.instance_hidden"/>
    </folder>
</folder>
<folder name="Toolbars_hidden"/>

<folder name="Windows2">
    <folder name="Modes">
        <file name="explorer.wsmode" url="explorer.wsmode"/>
        <folder name="explorer"/>
    </folder>   
    <file name="WindowManager.wswmgr" url="WindowManager.wswmgr"/>
</folder>

explorer.wsmode

<mode version="2.4">
<module name="org.netbeans.core.ui/1" spec="1.2" />
<name unique="explorer"  />
<kind type="view" />
<state type="joined"  />
<constraints>
    <path orientation="horizontal" number="20" weight="0.3"/>
    <path orientation="vertical" number="20" weight="0.5"/>
</constraints>
<bounds x="192" y="228" width="614" height="520" />
<frame state="0"/>
<active-tc  id="CustomerViewerTopComponent" />
<empty-behavior permanent="true"/></mode>

【问题讨论】:

  • 我不是 100% 确定,但是:我想如果你让你的 TopComponent 有一个最小尺寸(实现getMinimumSize() 以考虑你的图形)并在你的应用程序中激活“尊重最小尺寸” “品牌”属性那么这应该会自动发生。
  • 尊重最小尺寸只有在调整大小时才有效。我实际上已经尝试过了!!

标签: java swing netbeans netbeans-platform


【解决方案1】:

WindowManager.wswmgr 文件定义了主窗口的属性。您需要定义的另一部分是资源管理器模式(假设 CustomerViewer 窗口处于资源管理器模式)。

定义和注册模式类似于您定义和注册WindowManager.wswmgr 文件的方式。确定 xml 应该是什么样子的实用方法¹是运行应用程序,将分隔线移动到所需位置,关闭应用程序,然后从文件资源管理器&lt;Your_NB_Application&gt;/build/testuserdir/config/Windows2Local/Modes/explorer.wsmode 打开以下文件。

explorer.wsmode 中的内容复制到一个名为 explorer.wsmode 的文件中,您可以在模块的根包 (com.example.mymodule) 中创建该文件。现在你需要在你的图层文件中注册这个文件:

<folder name="Windows2"> 
    <file name="WindowManager.wswmgr" url="WindowManager.wswmgr"/> 
    <folder name="Modes">
        <file name="explorer.wsmode" url="explorer.wsmode"/>
        <folder name="explorer"/>
    </folder>        
</folder>

在再次运行之前,请务必在您的应用程序上运行“Clean and Build All”。

¹确定结构的正式方法是使用位于http://www.netbeans.org/dtds/mode-properties2_4.dtd的dtd

【讨论】:

  • 我系统中的路径不是&lt;Your_NB_Application&gt;/build/testuserdir/Windows2Local/Modes/explorer.wsmode.而是&lt;Your_NB_Application&gt;/build/testuserdir/config/Windows2Local/Modes/explorer.wsmode.
  • 我已经完成了这些步骤,但它仍然不起作用。我已将 layer.xml 和 explorer.wsmode 文件发布为编辑
  • 实际上被覆盖的 explore.wsmode 似乎什么也没做,甚至没有被识别...
  • 从您的编辑来看,您在复制explorer.wsmode 的内容之前似乎没有移动分隔线。很难相信 horizontal weight 属性在移动分隔线后可能正好是 0.3
  • 另外,请务必在您的应用程序上运行“Clean and Build All”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多