This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

[Netbeans] Integrating external Jpanel to a Jframe  RSS feed

Marco pase
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


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,
Lolo Mohammed
Posts: 13
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.. ;)
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!