Results 1 to 14 of 14
Thread: How do I add my JPanel
- 07-19-2010, 09:19 PM #1
Member
- Join Date
- Jul 2010
- Location
- UK, SW London
- Posts
- 4
- Rep Power
- 0
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.
- 07-29-2010, 12:02 PM #2
Member
- Join Date
- Jul 2010
- Location
- UK, SW London
- Posts
- 4
- Rep Power
- 0
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.
-
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!
- 07-30-2010, 08:47 AM #4
Member
- Join Date
- Jul 2010
- Location
- UK, SW London
- Posts
- 4
- Rep Power
- 0
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?
- 07-30-2010, 09:28 AM #5
Member
- Join Date
- Jul 2010
- Location
- Philippines
- Posts
- 3
- Rep Power
- 0
Hi Chanbre, project matisse is package with your netbeans IDE. You may do your entire design in there easily.
- 07-30-2010, 10:24 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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?
- 07-30-2010, 11:09 AM #7
Member
- Join Date
- Jul 2010
- Location
- Philippines
- Posts
- 3
- Rep Power
- 0
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.
- 07-30-2010, 11:19 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 07-30-2010, 11:22 AM #9
Member
- Join Date
- Jul 2010
- Location
- Philippines
- Posts
- 3
- Rep Power
- 0
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.
-
- 07-30-2010, 10:04 PM #11
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
- 07-30-2010, 10:09 PM #12
- 07-30-2010, 10:48 PM #13
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
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 likeIf 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.Java Code:public class ThisPanelIWantToUseFewTimes extends JPanel { // code here }Last edited by cselic; 07-30-2010 at 10:49 PM. Reason: typos
- 08-06-2010, 10:04 PM #14
Member
- Join Date
- Jul 2010
- Location
- UK, SW London
- Posts
- 4
- Rep Power
- 0
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
-
.add to a JPanel
By harrier in forum NetBeansReplies: 11Last Post: 07-13-2010, 10:24 AM -
JPanel
By Jitendra Shukla in forum AWT / SwingReplies: 11Last Post: 04-27-2010, 05:16 AM -
image in JPanel
By poojarkg in forum AWT / SwingReplies: 4Last Post: 04-26-2010, 05:52 PM -
I need some help with JPanel
By bantes in forum AWT / SwingReplies: 7Last Post: 11-03-2009, 07:58 PM -
How to use Jpanel
By Manfizy in forum NetBeansReplies: 0Last Post: 02-19-2009, 12:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks