I have a class called KeyBoard which extends JPanel. and it's a Screen Keyboard for the whole system and everywhere I need it, I just make an object and show it in a JPanel
there is the code I use,
in the form I have a Panel for Keybard called keyPanel, and KeyBoard is a separate class which extends JPanel and I made the keyBoard. so, I want to show the K object which is Child of JPanel inside the keyPanel which is a JPanel aswell.
it's strange, I can't understand what is happing. becuase it does not give any error, it runs totoaly okay, but does not show the keyboard.
Is the application showing you the wrapper panel ('keyPanel') at all? If not, try creating a JFrame and then adding the keyPanel to the JFrame and setting the JFrame visible.
If the application is showing your keyPanel, but the Keyboard you added does not appear, try adding
to the KeyBoard's constructor and try adding
to the frame's constructor.
Perhaps your keyboard is defaulting to a size of (0,0) because the layout manager you're using looks for a preferred size that you haven't specified. If that's the case, then adding the code shown above will reveal your keyboard panel. If this works, you can then customize the dimensions however you wish.
The application shows the Wrapper Panel and when I change the color, it change the color and working fine
and I tried your code and the the prefered size was 905, 311. Also with the minimize size.
It is still not working and it doesn't show at all, no error.
the only thing I could understand is, there is not any link at all between these two objects, although I tried to create and instantiat the object.
I have added in to KeyPanel , and change setVisible to true
but still not showing at all.
Thanks for your reply, if you got any other idea Please let me know.
first code for keyBoard Class, it's not completed though.
and it is the the section I want to call the the keyboard to be display, but I have to tell you. I have a dialog box inside that dialogbox I have many frames, one frame is called KeyPanel and I want the keyboard to be add in the keyPanel.
StaffView appears to be some sort of Dialog in which you're trying to show keyPanel. Just to be sure: where are you adding keyPanel to StaffView? I see that StaffView has a KeyPanel, and I see that you're adding the KeyBoard to that KeyPanel. However, I don't see in your code where you're adding keyPanel to its container. Simply possessing it isn't enough; you have to add it to something that will eventually be shown.
Your setVisible should be called on the outermost container (whether a JFrame or a Dialog).
I suggested setting a Preferred size on the KeyBoard and setting a minimum size on the containing Frame. It appears that you set both the Preferred and the Minimum on the KeyBoard panel. But this is contradictory since the preferred Dimension is smaller than the minimum. The proper placement would be to setPreferred on the panel and to setMinimum (which is larger) on its container (in this case, apparently the StaffView). The point of this was to ensure that your KeyBoard would not be obscured by sizing issues.
You might want to create some helper methods to handle all the repetitive code.
Joined: Dec 16, 2010
Hi Friends, David and Javad
First of All thank you very much for your help and it is appriciated.
Finally, I gave up calling the keyboard Panel to the dialogbox. I came up with new idea to make the keyboard in a new Frame and let the user call it when ever they want.
Finallay I manage to do so with your helps. thanks for that.
Although I have tried all the above suggestions, It did not work. I don't know why, although I have done this many times before. it might be some small issues. anyway for last time I have tried Davids suggestion. which is shown in the following code.
and preferedSize was set to keyBoard as well. but it did not work
finally I could get the keyPanel where I wanted the keyBoard to be displayed, but not the keyboard. then decided to leave it and try an alternative which works
I will post the solution here for people who struggles with.
Again Thanks for both of you.
subject: Cant show an object which extends JPanel in the form?