0

I am trying to learn some Java GUI stuff. I am trying to create a special jPanel, which I have created in another class [it is a Panel with two labels on it] inside one class, and using a passed JFrame add it to that JFrame from the other class. I have been trying myJFrame.add(thePanel) and such, but it never seems to actually do anything. I have tried doubly making sure it is sset to visible, is at a reasonable location, ect.

I am trying to create the panel in one class, and .add it to the given jframe. There is probably something I am not understanding.

I am not the best at the java GUI stuff... so please be kind :) Any advice you can give would be wonderful.

I am using Netbeans. If I drag the special Panel I created over to my panel in the Design editor, it adds an instance of that panel, but I can't seem to make my own instance of this and have it appear.

Andrej Istomin
  • 2,527
  • 2
  • 15
  • 22
  • 1
    Welcome to StackOverflow. It would be easier to answer your question if you would provide the code snippets that you are having a problem with. – serebit Apr 21 '16 at 23:51
  • 1
    *"and using a passed JFrame add it to that JFrame from the other class"* - Not sure I understand that ... and it worries me a little – MadProgrammer Apr 21 '16 at 23:58
  • *"I am trying to create the panel in one class, and .add it to the given jframe"* - Pass the `JPanel` back to the caller if possible and allow it to add it to the `JFrame` – MadProgrammer Apr 22 '16 at 00:00
  • Oh, so perhaps a better way to go about it would be to create a function in the JFrame, that adds one of these panels, and have my other class call the other function, passing what panel to create? Perhaps storing them all in some sort of list/array/ect of these panels. I think I was trying to go about this in too much of a Unity Engine instantiating a prefab mindset, but I think this new would work? The issue is I need to add an unknown number of these panels. Only adding one when the other class chooses to add it. – IvanDrago Apr 22 '16 at 00:12
  • 1
    1) Tip: Add @MadProgrammer (or whoever, the `@` is important) to *notify* the person of a new comment. 2) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 3) Provide ASCII art or a simple drawing of the *intended* layout of the GUI at minimum size, and if resizable, with more width and height. – Andrew Thompson Apr 22 '16 at 00:31
  • 1
    See also [*How to insert a JFreeChart chart in a panel on a separate GUI?*](http://stackoverflow.com/q/36752726/230513). – trashgod Apr 22 '16 at 02:12
  • "I am trying to learn some Java GUI stuff." Good. Start with the [Oracle tutorial for Swing](https://docs.oracle.com/javase/tutorial/uiswing/). Study the tutorial. Take 4 - 6 months to go through the tutorial and really learn Swing. Don't rush. Don't skip any tutorial sections. – Gilbert Le Blanc Apr 22 '16 at 06:27

0 Answers0