Efficiency in custom Map Editor - Swing or Graphics drawing?

Beginning a project on a game, and I decided I wanted to use my own in-house tools for development. And with that comes a Map Editor.

Since I will most likely be doing a lot of drawing with Graphics when I start to make the game itself, I thought this question was important to ask before I actually get to that part.

Currently, I am using Swing to make my Map Editor look pretty. I’ve got a JMenuBar, JToolBar, JSplitPanes, JScrollPanes, you name it. I’m actually pretty familiar with Swing and how to make it look nice.

So you can visualize it easier, here it is.

What you’re looking at is:

  • A JTabbedPane within my main Application’s JFrame, which has in it,
  • a JScrollPane, in order to allow proper viewing based on the zoom level of the
  • Custom Canvas JPanel set as the viewport, which has a specific LayoutManager, in order for the
  • Regular JPanel within the custom Canvas to be centered correctly, which contains
  • A GridBagLayout of JLabels.

Each JLabel has an icon based on whatever tile it should be. “Empty tiles” still have icons, it’s just that solid darker gray color, created by an ImageFactory class which stores all my image manipulation methods.


Okay, so if you’re still with me, I’d like to actually get around to asking my question.

My question: is using Swing components like this the most efficient way of doing this?

The reason I ask is, I’ve had to do a lot of setting and re-setting of each of those JLabels’ icon images. I’ve got one Class called ImageFactory that manipulates the images. The icons get changes based on Mouse input (clicking, enter, exit) or some other criteria, as such:

  • If no tile is selected to be ‘stamped,’ there will just be an alpha composite of a color painted over the JLabel’s icon to denote that it is being hovered, and will revert upon a MouseExit
  • If there is a tile on the active Stamp tool, that tile’s image will replace the JLabel’s icon -temporarily- to denote that it is being hovered, and will revert upon a MouseExit
  • If there is a tile on the active Stamp tool, and a JLabel is clicked, that JLabel’s icon will be set to the active Stamp tile “permanently” unless reverted
  • If the option to have Grid Lines is toggled on, each JLabel’s icon will be processed through the ImageFactory to have dashed lines running along the top and left edges (forms a grid, as seen in the picture)
  • If the Zoom level is changed, each JLabel’s preferredSize is set to accomodate, and the icon has to be resized in the ImageFactory (grid lines applied depending)

As you can see, this seems to be a lot of Icon changing/setting, and I don’t actually use any Graphics drawing (like I will within the game), except within the ImageFactory class (in order to manipulate the icons).

Is this the fastest or most efficient way to handle these things to achieve the desired outcome?

Would it be faster if I manually overrode the subclassed JPanel’s paintComponent method, and drew the stuff myself?

I know this still may seem trivial since I’ve got the thing working how I want. I’m just worried about making it as memory-efficient and CPU-efficient as possible. Even though the setting and re-setting of each JLabel’s icon happens pretty quickly, I need to be in this mindset because creating a game that is wasteful of resources is just bad practice, and I’ve never really had to make anything where I had to be nit-picky about these things.