ZephyrWolf
ZephyrWolf

Reputation: 17

JAVA: How can I add SWING components to my game HUD with custom textures

-- Little note, I attempted to upload an image of my game to illustrate my question, however I do not yet have the required reputation to do so. I apollogise for this.

I would like to create a drop down screen from the top HUD element on my game which the player can type into, effectively becoming a chat window, the actually window is not an issue and I understand that you can disable background and boarder rendering of Java's Swing components so that isn't an issue.

My question is simple, can I take advantage of java's Swing components like JTextField and position them exactly within the bounds of this area, without having to deal with java's layout classes. So this is a summary:

Upvotes: 0

Views: 315

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285460

Yes you can use a null layout on the container and call setBounds(...) on the component to MANUALLY place them. And this is usually a VERY BAD THING to do as it forces you to paint yourself into a layout corner making it very hard to upgrade or enhance your GUI later. It also guarantees that your GUI will look terrible on all platforms and screen resolutions other than one. Many newbies usually go this route initially, and then most leave it eventually after gaining more experience with Swing as they run into its failings, weaknesses and limitations.

For a more complete answer, consider giving more specifics and in image (we can help with this) of your GUI layout requirements.

Upvotes: 3

Related Questions