Ok Question, I have a GameBoard class(JPanel) which allows me to ingegrate w.e maps I want and w.e sprites to be loaded onto it, then this is put onto my JFrame class. For my GameBoard Class I painted a Custom image onto the JPanel by:

Question is, when I try to add a JLabel or JButton onto this GameBoard It keeps getting painted behind the Image. The reason I know this is If I don't paint an Image via commenting out g.drawImage(bg, 0,0,null); I get a regular background (blue) and my buttons and lables are there, so how do I make this Image the standard panes image?

I'm trying to put JButtons and JLabels on this panel and have them being painted over the background Image bg. In this class I paint sprites and the background and this gets put onto a JFrame where other UI components are.

I want to make the image bg the absolute background image instead of the panels raw color background. Pretty much I don't want the image bg to be painting over the other components? Is what i'm trying to achieve the wrong way of doing so?

@OPhttp://docs.oracle.com/javase/tutorial/uiswing/layout/using.htmlbasiclly, you define different JPanels and each one draws different thing. For your case, you need two JPanels. One to hold the swing components while other do Graphics draw. Then add both of them in single JPanel that using Layout (so you can adjust their position). The single JPanel that holds these two can be added to JFrame.

@OPhttp://docs.oracle.com/javase/tutorial/uiswing/layout/using.htmlbasiclly, you define different JPanels and each one draws different thing. For your case, you need two JPanels. One to hold the swing components while other do Graphics draw. Then add both of them in single JPanel that using Layout (so you can adjust their position). The single JPanel that holds these two can be added to JFrame.

Interesting I'll try this, thanks. Pretty much my game is an RPG and I want some npcs to have JLabels which pop up and i'd rather use java's built in components to do so instead of drawing rectangles and such manually. So what you're saying is the one with Sprites and Images is on one, then the swing components etc get put on a transparent JPanel which then gets added on top of the Images one?

Also Is there better industry standard for making "Buttons" and components than what I'm doing to achieve such?

Oh! if you mean label or button inside game world, then I suggest you to leave swing. I thought you want to create some HUD or what. Rather use JLabel or JButton, make one by your own - a class that receive Graphics parameter to draw text and background while keep updating its position (for example, above player's head).

Thanks yea, that is what I meant originally(thanks ill look more into that). Also, that does bring me back to a HuD, for now I have a panel that is adhesive to the main frame which has different buttons settings and has a custom painting on the panel, but to have a real HuD like what you originally thought I wanted, which I do but I coped out with a JPanel Holding buttons on the frame. TO do this like you say how do I prioritize A panel over a panel such as a HuD by which I mean fully transparent and can still allow clicks onto the main panel the game world? For example I would idealy like a HUD that hold a Portrait of the player with Health and one with action bars, and then eventually start menus and such.

Let's say a custom button. So this class acts like Entity, needs to be drawed. It can have fields like background image and position (x, y). A simple method to use this class: for example check if mouse click's point happened on top of this class. If yes, tell game state to do what this class have to do.

Alright thanks for the code, i'll read it over and try to understand it. So yea I guess that's what I have to learn to do is avoid Swing, and for HuDs and all GUI you would create everything from scratch like that button class?

So pretty much the only Swing Components you use are just Panels and frames just do the basics and that's it for game development for Swing*?

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org