Skip to content
Advertisement

How to make all images in Grid Overlay flush?

I am trying to implement a GUI for a maze-based game I created that meets the following specific conditions:

  1. The GUI itself has a set size and is not resizable (line 41) .

  2. The master panel (line 57) that contains all the maze images is scrollable. All maze image components are flush with each other.

    • If maze is small enough, then entire maze will be visible in master panel.
    • If maze is very large, then user would need to scroll.
  3. The master panel needs to be accessed by a mouse listener (line 130) that returns the component that is being clicked.

The following code seems to meet criteria 1 and 3, but fails criteria 2:

JavaScript

Here is an image of what it produces:

enter image description here

Advertisement

Answer

First, I’d make use of a different layout manager, one which would try and expand to fit the size of the underlying container.

Then, I would let the components do their jobs. I don’t know why you’re adding the label to another panel, the panel doesn’t seem to be adding additional functionality/features and is just adding to the complexity.

enter image description here

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement