开发者

Using existing Java Frame Form In another Window

I'm in the process of coding a little notepad-like application. I have a JFrame that I use to display statistics (word count, char count and all).

I'm wondering if it's possible for me to use that Frame in my main w开发者_开发知识库indow as a Stats Panel that I could just show or hide instead of having a new window to pop out.

I'm a real Java noobie so perhaps I'm just no using the right tools. I've tried putting my Frame in a SplitPane, Panel and Internal Frame without any luck.

Any and every suggestions would be highly appreciated.

Thanks!


A short cut is to get your JFrame's contentPane by calling getContentPane() on it, and then putting it where you want since it is a JPanel, but this is one reason why I think that folks should not code to the JFrame but rather to the JPanel. If instead your class was geared towards creating a JPanel from the very beginning, then you would have the flexibility of showing that panel in its own JFrame, in another JPanel as part of a more complex GUI, in a JDialog, a JApplet, or wherever you'd like.

So in sum, I suggest you re-write your GUI and gear it to make a JPanel. Also, if you're using NetBeans to create your GUI, you'll find that it may be less flexible compared to creating your GUI by hand with your own choice of layout managers since by doing it on your own, you can make your panel resize much more easily and cleanly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜