I'm making a 2D RTS Map Editor and here came the moment to make a Palette which is just a popup frame showing tiles to be clicked on and then applied on the map.
I'm wondering which Java Elements to use for this palette?
At the moment I have set a JFrame which will contain Jlabels which have their Icon set as some ImageIcon (which are the tiles of my game).
(I have a List<ImageIcon> tiles
which contains every tiles)
mainFrame.setLayout(new GridLayout(tiles.size() / 2, 2, 5,5));
JLabel tilePanel;
for (int i = 0; i < tiles.size() ; i++) {
tilePanel = new JLabel();
tilePanel.setIcon(tiles.get(i));
mainFrame.add(tilePanel);
}
Here's what I have:
However, I want to be able to click on these JLabels to be selected and so that I can use a function like getSelectedTile
in my main JFrame to place them on the Map. But adding a mouseListener/Event to each and every JLabel doesn't seem right.
My questions are:
Am I going the right way? If so, how should listen to my JLabels to know which tile is selected.
What SHOULD I use if this isn't the way to go?
Thanks in advance! All suggestions will be taken into consideration :)