Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to add custom component to a file that uses the Netbeans GUI editor (called: Matisse), there are several ways:</p> <p>First:</p> <p>You could add that component to the "Palette" manager. I, personally, have had limited success with this, especially when adding components from my own, custom libraries. However, you can add components and just select "from a project", then select your project and you should see your component listed (if you don't, run a clean &amp; build).</p> <p>Notice in this project I have two files, <code>CustomTextField</code> and <code>NewJFrame</code>.</p> <p><img src="https://i.stack.imgur.com/UWKor.jpg" alt="enter image description here"></p> <p>The code for CustomTextField is just something that extends a <code>JTextField</code>:</p> <pre><code>package test4; import javax.swing.JTextField; public class CustomTextField extends JTextField { } </code></pre> <p>Then, in the Palette window, you right click and click "Palette Manager..."</p> <p><img src="https://i.stack.imgur.com/BokQA.png" alt="enter image description here"></p> <p>Then in the Palette Manager, you click "Add from Project..." (if you are adding from a library, you click "Add from Library...", etc.</p> <p><img src="https://i.stack.imgur.com/bC7bX.jpg" alt="enter image description here"></p> <p>Then I select <code>CustomTextField</code></p> <p><img src="https://i.stack.imgur.com/uVLaP.jpg" alt="enter image description here"></p> <p>And boom there it is in the Palette Manager, and I can drag &amp; drop it into my GUI.</p> <p><img src="https://i.stack.imgur.com/VPHFh.png" alt="enter image description here"></p> <p>Note: this way is not very good if you need this component across <strong>multiple projects.</strong> The palette manager is for Netbeans as a whole, so if you try to use a component that exists in another project, you'll have trouble.</p> <p>Note #2: I had problems with Java Web Start and my own custom library. <a href="https://stackoverflow.com/questions/17230773/java-7-update-25-makes-our-java-web-start-application-fail-with-no-logging">There is a bug that was released with 7u25 that causes a NPE from the JNLPClassLoader</a> whenever my custom libraries are loaded, so I had to import the components from a Project instead of a Library.</p> <p>Second:</p> <p>There is a more hackish way of doing things, but sometimes it's necessary: In the GUI-editor, you can right-click the component and click "Customize code."<img src="https://i.stack.imgur.com/1jqbV.png" alt="enter image description here"> You can then change the variable definition (<a href="http://www.cprogramming.com/declare_vs_define.html" rel="nofollow noreferrer">not the declaration</a>). If you need to change the variable <strong>declaration</strong>, then it gets even MORE hackish, and I would recommend you just hand-write your code at that point. But, to do it through this window, you can "comment off" the portion in "variable declaration code" by adding <code>/*</code> and <code>*/</code> around <code>private javax.swing.JTextField jTextField1;</code> and add your own variable declaration.</p> <p>Third:</p> <p>Your other option is to hand write. :) If you need simple Swing components or components that can be added to the palette, I recommend the GUI Editor. If you need more complex and customized Swing components, then you'll want to start hand writing this code. Most people will recommend you do so anyways. <a href="https://stackoverflow.com/questions/468328/java-gui-builder-or-hand-coding/17581918#17581918">I, however, proudly love Netbeans` GUI Editor.</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload