File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes [Netbeans] Integrating external Jpanel to a Jframe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "[Netbeans] Integrating external Jpanel to a Jframe" Watch "[Netbeans] Integrating external Jpanel to a Jframe" New topic
Author

[Netbeans] Integrating external Jpanel to a Jframe

Marco pase
Greenhorn

Joined: Oct 03, 2009
Posts: 4
Goodmorning,
I don't even know if this title is appropriate or not, this thing is getting me mad.

I'm building a GUI using Netbeans, and i created a JPanel with some components to perform a search in some different contests. i would like to integrate this Panel into a few different JFrames instead of copy-pasting the same code in every frame.
Now, the Netbeans' GUI Builder only lets me insert components by dragging them out of the palette, so i dragged out an empty panel to the right position in the frame and i changed its initialization from



to



so that empty panel should magically become my SearchPanel at runtime. And this is actually happening, but no components are being painted into the SearchPanel.
If i override the Paint(Graphics g) method of my SearchPanel like this



to draw a line in the background, the line is successfully drawn at runtime, so i'm sure that the empty panel is actually changed to SearchPanel, but still i can see no components.

What am i doing wrong?
Eventually, is there a cleaner way to create (with netbeans) a custom panel (or any other swing component) and use it in many different frames, dialogs, panels etc... in the same project?

Thanks in advance,
Greetings
Lolo Mohammed
Greenhorn

Joined: Mar 17, 2011
Posts: 13

Hello,

I have the same problem

I have to clasess
1- the first class extends JPanel
2- the second class extends Jframe

I try to add the JPanel class inside the frame , but the frame is appear empty.

There is away to solve this problem but it is not usfull for me because I need Jframe class (extends JFrame) to make the fram design easier.

you can use normal class insted of extends JFrame, then you can define frame in the main class and add the panel in to it.

like this:



I hope this will help you...

if you found another solution please inform me.. ;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Netbeans] Integrating external Jpanel to a Jframe
 
Similar Threads
Please check if the paint method used properly
not able to get the coloured oval
JPanel Form Problems
How to Draw a Line in Java?
full-screen gray window problem and event handling problem