java - GridBagConstraints insert a shifted column? -
i'm using gridbaglayout , gridbagconstraints create map (grid of texture)
but want insert border between different texture: want
|-----|-----|-----| |-----|-----|-----| |----|-|----|-----| |-----|-----|-----| 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 same texture, want them cutting off 1 position @ border
@ code-guru interest. found different way solve problem: is, cutting image bufferedimage. i'll post alter 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);
i think, need start grid has 5 columns per row. each row, need specify how many columns each cell span.
for first, sec , 4th row in example, first cell spans 2 columns, sec cell spans 2 columns , lastly cell spans 1 column. 3rd row, first, third, , 4th cells span single column , sec cell spans 2 columns.
p.s. implement phone call "spanning" here using gridwidth fellow member of gridbagconstraints objects. can set constructor or directly.
java map constraints textures gridbaglayout
No comments:
Post a Comment