Results 1 to 14 of 14
  1. #1
    Chanbre is offline Member
    Join Date
    Jul 2010
    Location
    UK, SW London
    Posts
    4
    Rep Power
    0

    Default How do I add my JPanel

    Using the Netbeans design editor I have created a JPanel (as "public class LengthPanel extends javax.swing.JPanel {...}" ) containing a few items. Now I want to place two copies of that panel into the JPanel of the main form of my program. How do I do this? I cannot work out what question to ask of web search engines.

    What I really want is a have data entry gadgets for height and width. Each can be entered as metric (one number) or imperial (two numbers) values with its own JComboBox to choose. I want to design and code one length-entry gadget and have two copies of it.

  2. #2
    Chanbre is offline Member
    Join Date
    Jul 2010
    Location
    UK, SW London
    Posts
    4
    Rep Power
    0

    Default

    One answer may be using Java Beans and place my panel into a bean. But that is not the answer I want at the moment. My panel is not useful as a gadget in its own right, it belongs entirely to my little application. Furthermore, the descriptions of beans within Netbeans says that they are separately compiled. I wanted to build one application that can be compiled and debugged as a single simple set of sources.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Read the Sun/Oracle Swing tutorials and it will tell you have to add JPanels to other JPanels and to the contentPanes of root containers such as JFrames. The key is often to understand how to use the various layout managers, and the tutorials will explain all about that.

    Much luck!

  4. #4
    Chanbre is offline Member
    Join Date
    Jul 2010
    Location
    UK, SW London
    Posts
    4
    Rep Power
    0

    Default

    Thank you for the reply, Fubarable. I believe I have read enough of the tutorials to understand how to do the work in Java + Swing. However my question concerns Netbeans.

    Using Netbeans how do I make a JPanel (or some other type of class) so I can place two copies of it onto my program?

  5. #5
    jrdumayag is offline Member
    Join Date
    Jul 2010
    Location
    Philippines
    Posts
    3
    Rep Power
    0

    Default

    Hi Chanbre, project matisse is package with your netbeans IDE. You may do your entire design in there easily.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default

    Not having done more than a brief play with the Netbeans GUI builder I'm possibly not the most qualified, but I don't think Netbeans is intended to work like that?

    If I understand you correctly you have a widget in the form of a JPanel that contains some fields. You want to use this widget in several places (which is always nice to see) on your main screen. I hand carve my Swing stuff (when I get a chance to do it anyway), rather than rely on a builder, so reusing stuff is second nature.

    Can I ask why you're using the GUI builder?

  7. #7
    jrdumayag is offline Member
    Join Date
    Jul 2010
    Location
    Philippines
    Posts
    3
    Rep Power
    0

    Default

    Not that i used extensively the netbeans gui builder, I think it may also benefit others as it exposes the layout code and other methods on how you add components to panel/jpanel.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default

    I'm not cinvinced that it does a particularly good job on code layout.
    At least I don't write stuff anything like the builder does...but that might be the various Layouts I tend to use.

  9. #9
    jrdumayag is offline Member
    Join Date
    Jul 2010
    Location
    Philippines
    Posts
    3
    Rep Power
    0

    Default

    Maybe it does at least for me. But I agree, coll stuff should be handcrafted rather that copied and pasted. Well, using matisse maybe a good start I guess.Just a good start.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Chanbre View Post
    Thank you for the reply, Fubarable. I believe I have read enough of the tutorials to understand how to do the work in Java + Swing. However my question concerns Netbeans.

    Using Netbeans how do I make a JPanel (or some other type of class) so I can place two copies of it onto my program?
    You can still combine hand-crafted Swing code with NetBeans, and I think to solve your problem this is just precisely what you're going to have to do.

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,421
    Rep Power
    20

    Default

    Or read the NetBeans help ... there's a topic titled "Adding a Bean to the Palette Window"

    I sometimes wonder why they bothered to provide a help file at all.

    db

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,421
    Rep Power
    20

    Default

    Quote Originally Posted by Chanbre View Post
    One answer may be using Java Beans and place my panel into a bean. But that is not the answer I want at the moment. My panel is not useful as a gadget in its own right, it belongs entirely to my little application. Furthermore, the descriptions of beans within Netbeans says that they are separately compiled. I wanted to build one application that can be compiled and debugged as a single simple set of sources.
    OK I missed this, sorry.

    db

  13. #13
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    I don't use netbeans but I want to say few words :D

    if you want to use JPanel few times then, I think, you should write it as an object of class that extends JPanel class.

    something like
    Java Code:
    public class ThisPanelIWantToUseFewTimes extends JPanel { // code
     here }
    If you want to write class that it could be used separate, independent in programs then, I guess, you should write an interface that gives some kind of "protocol for communication" with other classes.
    Last edited by cselic; 07-30-2010 at 11:49 PM. Reason: typos

  14. #14
    Chanbre is offline Member
    Join Date
    Jul 2010
    Location
    UK, SW London
    Posts
    4
    Rep Power
    0

    Default

    Thanks for all the comments folks.

    jrdumayag suggested using "matisse". I believe that this is the GUI builder within Netbeans and so it is the target of my question: How do I use it to create two copies of the same panel to give two objects.

    Tolls asked why am I using the GUI builder. It is advertised as a major facility of Netbeans. Several IDEs offer GUI builders and GUI editors that are intended to make it easy to create the GUI for a program. Almost all of I what I need can easily be built with the Netbeans GUI editor. I just want to know how to do a little bit of component reuse. Tolls also said that with his "... hand carve[d] ... swing stuff ... reusing stuff is second nature." and that is what I would like to achieve, but using Netbeans.

    Darryl's first comment is interesting, I know you partially retracted it but I would like to respond. The Netbeans help is extensive but not always good as an introduction. The topic title "Adding a Bean to the Palette Window" may be relevant but it has no obvious association with what I wanted to do. Initially I found nothing to suggest that I should learn about beans. The Netbeans 6.9 help system does not have an index page, searching it for "bean" or "beans" provides a list of topics that bear little obvious relationship to what I am trying to do. Adding something to the Pallette Window sounds like extending or customising Netbeans, it does not sound like routine simple stuff for creating part of a program. On Darryl's second comment, no apology needed.

    cselic's comment about extending a JPanel matches, I believe, exactly what I said I had done in my original question. I do not understand the implications of his second comment about the ""protocol for communication" with other classes". I think that that takes things way beyond what I had thought to be a simple question about building GUIs with the Netbeans GUI editor.

    The Netbeans tutorials go into great details of select-this, click-that, drag-something else, type another thing and so on. It seems to me they give too much detail. I have not found tutorials that give outlines of how to do things.

    Again, my thanks to all of you.

Similar Threads

  1. .add to a JPanel
    By harrier in forum NetBeans
    Replies: 11
    Last Post: 07-13-2010, 11:24 AM
  2. JPanel
    By Jitendra Shukla in forum AWT / Swing
    Replies: 11
    Last Post: 04-27-2010, 06:16 AM
  3. image in JPanel
    By poojarkg in forum AWT / Swing
    Replies: 4
    Last Post: 04-26-2010, 06:52 PM
  4. I need some help with JPanel
    By bantes in forum AWT / Swing
    Replies: 7
    Last Post: 11-03-2009, 08:58 PM
  5. How to use Jpanel
    By Manfizy in forum NetBeans
    Replies: 0
    Last Post: 02-19-2009, 01:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •