aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Cant show an object which extends JPanel in the form? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Cant show an object which extends JPanel in the form?" Watch "Cant show an object which extends JPanel in the form?" New topic
Author

Cant show an object which extends JPanel in the form?

Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hi Friends;

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.
David Byron
Rancher

Joined: Jan 20, 2009
Posts: 172

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.


OCMJD 6, OCPJP7, Baroque Potion, G+
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hi David

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.

Javad Rashidi
Ranch Hand

Joined: Feb 13, 2011
Posts: 34

hi farhad, could you post your complete code here?


http://www.myviwo.com
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hi Javad,

there you go my friend.

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.



I hope, you could understand.

cheers.
Farhad
Javad Rashidi
Ranch Hand

Joined: Feb 13, 2011
Posts: 34

What is the layout of KeyPanel?
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
I think, it is the default one.

I am not sure.

I am using netbeans as you can see most of the code is generate, I only use the GUI builder.

but it shows the free design. there is not thing in KeyPanel. I just add that as a place for the keyBoard which is indeed a JPanel. I have tried to put JPanel inside JPanel.
the hierarchy is like

first the application
second the JDialogBox
third mainPanel
fourth KeyPanel
and the final should be keyboard. Lolz

but its not coming.
Javad Rashidi
Ranch Hand

Joined: Feb 13, 2011
Posts: 34

i test your code. i think you should use setSize(int width , int height) for mainPanel if the KeyPanel added to it and set the layout of DialogBox to null.
something like this
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hey Javad,

I just tried, it is not working.

I didn't have mainPanel there, there are four Panels in the diaglogBox. one of them is the keyPanel.

okay, no worries about it. if you got any other idea, how make it work or any other alternatives for this. Please let me know,

Thanks
Farhad
Javad Rashidi
Ranch Hand

Joined: Feb 13, 2011
Posts: 34

have you tried setSize and setPreferredSize for KeyPanel, set both for your KeyPanel and if it didn't work change the layout of JDialogBox to null.
you can do this:
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hey Javad

Many Thanks for your help.

I have tried everything, it's still not working. I don't know why. I have done it many time with other projects.
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
I am just thinking to not add it in to the JDialog Box.

instead, I want to add it in a new window, when the each text box is get focused in the application, the key board windows should appear and let the user to write.

but the problem is, when the keyboard appears in a new window. it gets focus and the text box in the pervious window loses focus.

to be more clear, I want something like windows screen keyboard.

any idea?
Javad Rashidi
Ranch Hand

Joined: Feb 13, 2011
Posts: 34

you can make a JFrame un focusable by useing these method


hope this help.
Javad Rashidi
Ranch Hand

Joined: Feb 13, 2011
Posts: 34

why you want that text box keep focus?
David Byron
Rancher

Joined: Jan 20, 2009
Posts: 172

Farhad Rahmati wrote:


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.

Other observations:

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.

Good luck!
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Cant show an object which extends JPanel in the form?