I'm using GridBagLayout and GridBagConstraints to create a map (grid of texture)
but now I want to insert an edge between different texture: I want something like this
|-----|-----|-----|
|-----|-----|-----|
|----|-|----|-----|
|-----|-----|-----|
i have tried:
c.gridx = i*5;
c.gridy = j*5;
c.gridwidth = 5;
c.gridheight = 5;
if(right != null && right != currentTexture)
c.gridwidth--;
if(left != null && left != currentTexture){
c.gridx = i*5+1;
c.gridwidth--;
}
but I'm getting this:
I'm using the same texture, but I want them to be cut off 1 position at the edge
@ Code-Guru Thanks for your interest. I found a different way to solve my problem: that is, cutting the image with the BufferedImage. I'll post the change to my code:
ImageIcon tile = //get texture ...
Image img = tile.getImage();
BufferedImage buff = new BufferedImage(tile.getIconWidth(),tile.getIconHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = buff.createGraphics();
g.drawImage(img,0,0,null);
int w = tile.getIconWidth(), h = tile.getIconHeight();
int x = 0, y = 0;
c = new GridBagConstraints();
c.gridx = i*10;
c.gridy = j*10;
c.gridwidth = 10;
c.gridheight = 10;
c.fill = GridBagConstraints.NONE;
if(right != null && right != texture){
//c.gridwidth--;
c.anchor = GridBagConstraints.WEST;
w -= (int)(res.ordinal()*2.5+2.5);
}
if(left != null && left != texture){
//c.gridx = (i*10)+1;
//c.gridwidth--;
x = (int)(res.ordinal()*2.5+2.5);
w -= (int)(res.ordinal()*2.5+2.5);
if(c.anchor == GridBagConstraints.WEST)
c.anchor = GridBagConstraints.CENTER;
else
c.anchor = GridBagConstraints.EAST;
}
BufferedImage buff2 = buff.getSubimage(x, y, w, h);
JLabel l = new JLabel(new ImageIcon(buff2));
globalMap.add(l, c);