1

How can I set the size of my TopComponent window open in editor mode with my Netbeans Platform Application programmatically? I already tried setSize(500,500) in the constructor but it didn´t work.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bruno Barros
  • 409
  • 4
  • 14

1 Answers1

1

I am not really sure whether this will be helpful but a module can include changes to the settings in layer.xml that change the size/position of the modes starting position. Your top-component will be docked in one of the modes so changing its size should change your top-components size.

eg layer.xml in your module:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
    <folder name="Windows2">
        <folder name="Modes">
            <file name="editor.wsmode" url="modesettings.xml"/>
        </folder>
    </folder>
</filesystem>

this points to a modesettings.xml in the same directory.

<?xml version="1.0" encoding="UTF-8"?>
<mode version="2.4">
    <module name="org.netbeans.core.ui/1" spec="1.2"/>
    <name unique="editor"/>
    <kind type="view"/>
    <state type="separated"/>
    <constraints>
        <path orientation="horizontal" number="20" weight="0.3"/>
        <path orientation="vertical" number="20" weight="0.5"/>
    </constraints>
    <bounds x="137" y="192" width="660" height="200"/>
    <frame state="0"/>
    <empty-behavior permanent="true"/>
</mode>

You can also change the Mode bounds at startup with something like this:

@OnShowing
public class ModeBoundsSetter implements Runnable {

    @Override
    public void run() {
        WindowManager wm = WindowManager.getDefault();
        Mode mode = wm.findMode("editor");
        if(null != mode) {
            mode.setBounds(new Rectangle(0,0,2000,100));
        }
    }
}
WillShackleford
  • 6,918
  • 2
  • 17
  • 33
  • Tks, but it didn´t work. In my layer.xml file, the node doesn´t have children nodes. I´ve also looked for every file in the xml layer and didn´t find nothing like your modesettings.xml file. I´m trying to do it like you said in your third block of code snippet, but it also didn´t work. The window always remains with the same size. – Bruno Barros Oct 26 '15 at 21:32
  • 1
    If your layer.xml doesn't have child nodes you need to add them as I did. It is not surprising you don't have a modesettings.xml as I just made up that name. You can choose any name you want for modesettings.xml. It just has to match so the layer.xml file tells it to look in modesettings.xml or whatever you name it. For the third block you need to run it in a runnable public class with the `@OnShowing` annotation. – WillShackleford Oct 26 '15 at 21:45
  • I put the `@OnShowing` annotation before the `TopComponent` class declaration and implemented the `Runnable` interface in the same class. I put the same snippet of code inside the `run()` and it even didn´t work. I´m gonna try to add that children nodes inside my layer.xml and also create a xml in the same directory as you said. Then I´ll post the result in a minute. – Bruno Barros Oct 26 '15 at 22:18
  • It may require a clean and build to avoid using the cached state from your last run. – WillShackleford Oct 26 '15 at 22:27
  • It did work when shown up for the first time. After dock it and float again, it ignored the changes in the size and position set in the xml file. – Bruno Barros Oct 26 '15 at 22:33