The situation is , I merged all the five cells of the first row and inserted an image to the first cell of the first row. My requirements is to make the image horizontally centered for the first row.
I've tried cellStyle.setAlignment(CellStyle.ALIGN_CENTER); but it centers text not images.
Can anyone help?
Note: all the cells have different widths.
Positioning a image in an Excel sheet is a tricky thing since the picture is anchored on two cells. The upper left anchor cell plus a delta-x and a delta-y to this determines the position of the upper left edge of the picture. The bottom right anchor cell plus a delta-x and a delta-y to this determines the size.
Whether cells are merged or not is not important for this process.
So for centering horizontally we need to calculate which is the upper left anchor cell plus a delta-x to this. Fortunately the bottom right anchor cell plus a delta-x and a delta-y to this can be determined automatically through resizing the image to its original size after the upper left anchor cell is set. Of course only if the picture shall appear in its original size.
Example with comments:
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.*;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Units;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
class CenterImageTest {
public static void main(String[] args) {
try {
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet1");
//create the cells A1:F1 with different widths
Cell cell = null;
Row row = sheet.createRow(0);
for (int col = 0; col < 6; col++) {
cell = row.createCell(col);
sheet.setColumnWidth(col, (col+1)*5*256);
}
//merge A1:F1
sheet.addMergedRegion(new CellRangeAddress(0,0,0,5));
//load the picture
InputStream inputStream = new FileInputStream("/home/axel/Bilder/Unbenannt.png");
byte[] bytes = IOUtils.toByteArray(inputStream);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
inputStream.close();
//create an anchor with upper left cell A1
CreationHelper helper = wb.getCreationHelper();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(0); //Column A
anchor.setRow1(0); //Row 1
//create a picture anchored to A1
Drawing drawing = sheet.createDrawingPatriarch();
Picture pict = drawing.createPicture(anchor, pictureIdx);
//resize the pictutre to original size
pict.resize();
//get the picture width
int pictWidthPx = pict.getImageDimension().width;
System.out.println(pictWidthPx);
//get the cell width A1:F1
float cellWidthPx = 0f;
for (int col = 0; col < 6; col++) {
cellWidthPx += sheet.getColumnWidthInPixels(col);
}
System.out.println(cellWidthPx);
//calculate the center position
int centerPosPx = Math.round(cellWidthPx/2f - (float)pictWidthPx/2f);
System.out.println(centerPosPx);
//determine the new first anchor column dependent of the center position
//and the remaining pixels as Dx
int anchorCol1 = 0;
for (int col = 0; col < 6; col++) {
if (Math.round(sheet.getColumnWidthInPixels(col)) < centerPosPx) {
centerPosPx -= Math.round(sheet.getColumnWidthInPixels(col));
anchorCol1 = col + 1;
} else {
break;
}
}
System.out.println(anchorCol1);
System.out.println(centerPosPx);
//set the new upper left anchor position
anchor.setCol1(anchorCol1);
//set the remaining pixels up to the center position as Dx in unit EMU
anchor.setDx1( centerPosPx * Units.EMU_PER_PIXEL);
//resize the pictutre to original size again
//this will determine the new bottom rigth anchor position
pict.resize();
FileOutputStream fileOut = new FileOutputStream("CenterImageTest.xlsx");
wb.write(fileOut);
fileOut.close();
} catch (IOException ioex) {
}
}
}
For a scaled picture have a scale factor:
double scaleFactor = 0.25d;
and then:
//calculate the center position
int centerPosPx = Math.round(cellWidthPx/2f - (float)pictWidthPx/2f*(float)scaleFactor);
and:
//resize the pictutre to original size again
//this will determine the new bottom rigth anchor position with original size
pict.resize();
//resize the pictutre to scaled size
//this will determine the new bottom rigth anchor position with scaled size
pict.resize(scaleFactor);
Note: Resize to original size first. So determine bottom right anchor position with original size. Then resize scaled. So get bottom right anchor position with scaled size.
Related
I'm trying to draw underline and topline by drawing a line in a cell, but I don't know how. I need to draw two straight lines to implement it.
Sheet sheet = workbook.getSheetAt(2);
XSSFDrawing patriarch = (XSSFDrawing) sheet.createDrawingPatriarch();
XSSFClientAnchor regionr = patriarch.createAnchor(0, 0, 1, 1, 5, 5, 6, 6);
XSSFSimpleShape region1Shapevr = patriarch.createSimpleShape(regionr);
region1Shapevr.setLineStyleColor(10, 10, 10);
region1Shapevr.setFillColor(90, 10, 200);
region1Shapevr.setLineWidth(1);
region1Shapevr.setLineStyle(0);
region1Shapevr.setShapeType(ShapeTypes.LINE);
The current code gives the following result
Here is the desired result
As commented already main suggestion to you is to use cell border lines instead of line shapes. Cell border lines are one of the main features of a spreadsheet. Shapes are not. That's why shapes are much more complicated to use than cell border lines.
But of course drawing line shapes is possible.
The position and size of the shapes is determined by the anchor. One can think about shapes floating in the drawing layer over the cells. The anchor anchors them on the cell edges. According to the positions of the cells they are anchored to, shapes also will stretched or compressed. So also the size is determined by the anchor.
A ClientAnchor has following properties:
Col1 = top left edge of the shape is ancored on left edge of that column
Row1 = top left edge of the shape is ancored on top edge of that row
Col2 = bottom right edge of the shape is ancored on left edge of that column
Row2 = bottom right edge of the shape is ancored on top edge of that row
Dx1 = delta x to shift top left edge of the shape away from the left edge of the Col1
Dy1 = delta y to shift top left edge of the shape away from the top edge of the Row1
Dx2 = delta x to shift bottom right edge of the shape away from the left edge of the Col2
Dy2 = delta y to shift bottom right edge of the shape away from the top edge of the Row2
Note, measurement unit for dx and dy is EMU (English Metric Unit). There is Units to handle those strange measurement units properly.
Complete example:
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.util.Units;
import java.io.FileOutputStream;
class CreateExcelLineShapesParallel {
static void drawLine(XSSFDrawing xssfdrawing, XSSFClientAnchor xssfanchor) {
XSSFSimpleShape xssfshape = xssfdrawing.createSimpleShape(xssfanchor);
xssfshape.setShapeType(ShapeTypes.LINE);
xssfshape.setLineWidth(1);
xssfshape.setLineStyle(0);
xssfshape.setLineStyleColor(0, 0, 0);
}
static ClientAnchor getAnchorHorizontalFromCell(CreationHelper helper, Cell cell) {
//anchor determines the size of the line shape to be from
//upper left edge of cell to upper left edge of next cell in row
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setRow1(cell.getRowIndex());
anchor.setCol2(cell.getColumnIndex()+1);
anchor.setRow2(cell.getRowIndex());
//dx and dy in anchor to shift it away from the edges of the cell
//all initialized to 0
anchor.setDx1(0);
anchor.setDx2(0);
anchor.setDy1(0);
anchor.setDy2(0);
return anchor;
}
public static void main(String[] args) throws Exception{
Workbook workbook = new XSSFWorkbook(); String filePath = "./CreateExcelLineShapesParallel.xlsx";
CellStyle style = workbook.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
Sheet sheet = workbook.createSheet("Sheet1");
int rowHeightInPt = 30;
int lineMarginTopAndBottomInPt = 5;
Row row = sheet.createRow(5);
row.setHeightInPoints(rowHeightInPt);
Cell cell = row.createCell(5);
cell.setCellValue("Hello");
cell.setCellStyle(style);
CreationHelper helper = workbook.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = getAnchorHorizontalFromCell(helper, cell);
//dx and dy in anchor to shift it away from the edges of the cell
//measurement unit for dx and dy is EMU (English Metric Unit)
anchor.setDy1(Units.toEMU(lineMarginTopAndBottomInPt));
anchor.setDy2(Units.toEMU(lineMarginTopAndBottomInPt));
//draw a line positioned by the anchor.
drawLine((XSSFDrawing)drawing, (XSSFClientAnchor)anchor);
anchor = getAnchorHorizontalFromCell(helper, cell);
anchor.setDy1(Units.toEMU(rowHeightInPt-lineMarginTopAndBottomInPt));
anchor.setDy2(Units.toEMU(rowHeightInPt-lineMarginTopAndBottomInPt));
drawLine((XSSFDrawing)drawing, (XSSFClientAnchor)anchor);
FileOutputStream out = new FileOutputStream(filePath);
workbook.write(out);
out.close();
workbook.close();
}
}
I'm trying to adjust combo list width based on list content maximum width.
what are all the possible ways to increase/decrease width of combo list dynamically depends upon on the list items maximum width.
I have used this:
void SetBestDroppedWidth(CComboBox *pComboBox)
{
// Find the longest string in the combo box.
CString str;
CSize sz;
int dx = 0;
TEXTMETRIC tm;
CDC* pDC = pComboBox->GetDC();
CFont* pFont = pComboBox->GetFont();
// Select the listbox font, save the old font
CFont* pOldFont = pDC->SelectObject(pFont);
// Get the text metrics for avg char width
pDC->GetTextMetrics(&tm);
for (int i = 0; i < pComboBox->GetCount(); i++)
{
pComboBox->GetLBText(i, str);
sz = pDC->GetTextExtent(str);
// Add the avg width to prevent clipping
sz.cx += tm.tmAveCharWidth;
if (sz.cx > dx)
dx = sz.cx;
}
// Select the old font back into the DC
pDC->SelectObject(pOldFont);
pComboBox->ReleaseDC(pDC);
// Adjust the width for the vertical scroll bar and the left and right border.
dx += ::GetSystemMetrics(SM_CXVSCROLL) + 2 * ::GetSystemMetrics(SM_CXEDGE);
// If the width of the list box is too small, adjust it so that every
// item is completely visible.
if (pComboBox->GetDroppedWidth() < dx)
{
pComboBox->SetDroppedWidth(dx);
ASSERT(pComboBox->GetDroppedWidth() == dx);
}
}
Call it efter all the items have been added to the combobox:
//CComboBox m_HavingRole; // in header file
for (RoleList::iterator it = rolesObList.begin(); it != rolesObList.end(); it++)
{
nItem = m_HavingRole.AddString(it->m_szName);
m_HavingRole.SetItemData(nItem, it->m_lRoleID);
}
SetBestDroppedWidth(&m_HavingRole);
I know this question might seem similar but I have different problem. I know how to create a circle or a shape. This is what I want to create
A little circle in the center of the excel cell
The circle that I am able to make, looking at tutorials etc is:
This is the code I am using to create:
CreationHelper helper = workbook.getCreationHelper();
Drawing drawing = worksheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(0);
anchor.setRow1(0);
anchor.setCol2(1);
anchor.setRow2(1);
anchor.setDx1(255);
anchor.setDx2(255);
anchor.setDy1(0);
anchor.setDy2(0);
XSSFSimpleShape shape = ((XSSFDrawing)drawing).createSimpleShape((XSSFClientAnchor)anchor);
shape.setShapeType(ShapeTypes.FLOW_CHART_CONNECTOR);
shape.setFillColor(255, 0, 0);
I think there is something to do with the dx1,dx2,dy1,dy2 but setting any value in there has no effect.
I need to make that shape smaller somehow
If the shape shall within one cell only then the anchor must also be only one cell. The positioning is done then with Dx and Dy. But the measurement unit is special. It is EMU English Metric Units.
So the positioning of an ellipse in cell A1 will be like so:
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.util.Units;
import java.io.FileOutputStream;
import java.io.IOException;
class CenterShapeInCell {
public static void main(String[] args) {
try {
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet1");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
row.setHeight((short)(20*20));
sheet.setColumnWidth(0, 20*256);
CreationHelper helper = workbook.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
//set anchor to A1 only
anchor.setCol1(0);
anchor.setRow1(0);
anchor.setCol2(0);
anchor.setRow2(0);
//get the cell width of A1
float cellWidthPx = sheet.getColumnWidthInPixels(0);
System.out.println(cellWidthPx);
//set wanted shape size
int shapeWidthPx = 20;
int shapeHeightPx = 20;
//calculate the position of left upper edge
float centerPosPx = cellWidthPx/2f - (float)shapeWidthPx/2f;
System.out.println(centerPosPx);
//set the position of left edge as Dx1 in unit EMU
anchor.setDx1(Math.round(centerPosPx * Units.EMU_PER_PIXEL));
//set the position of right edge as Dx2 in unit EMU
anchor.setDx2(Math.round((centerPosPx + shapeWidthPx) * Units.EMU_PER_PIXEL));
//set upper padding
int upperPaddingPx = 4;
//set upper padding as Dy1 in unit EMU
anchor.setDy1(upperPaddingPx * Units.EMU_PER_PIXEL);
//set upper padding + shape height as Dy2 in unit EMU
anchor.setDy2((upperPaddingPx + shapeHeightPx) * Units.EMU_PER_PIXEL);
XSSFSimpleShape shape = ((XSSFDrawing)drawing).createSimpleShape((XSSFClientAnchor)anchor);
shape.setShapeType(ShapeTypes.ELLIPSE);
shape.setFillColor(255, 0, 0);
FileOutputStream fileOut = new FileOutputStream("CenterShapeInCell.xlsx");
workbook.write(fileOut);
fileOut.close();
} catch (IOException ioex) {
}
}
}
Looks like:
But I suspect what you really want is a conditional formatting with traffic light symbols like so:
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import java.io.FileOutputStream;
import java.io.IOException;
class ConditionalFormattingIconSet {
public static void main(String[] args) {
try {
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet1");
CellStyle cellStyle = workbook.createCellStyle();
//cellStyle.setAlignment(CellStyle.ALIGN_CENTER); // old apache poi versions
cellStyle.setAlignment(HorizontalAlignment.CENTER); // current apache poi version 4.1.0
//cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); // old apache poi versions
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // current apache poi version 4.1.0
Cell cell;
for (int i = 0; i < 3; i++) {
cell = sheet.createRow(i).createCell(0);
cell.setCellValue(1+i);
cell.setCellStyle(cellStyle);
}
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
ConditionalFormattingRule rule = sheetCF.createConditionalFormattingRule(IconMultiStateFormatting.IconSet.GYR_3_TRAFFIC_LIGHTS);
rule.getMultiStateFormatting().setIconOnly(true);
ConditionalFormattingRule [] cfRules = {rule};
CellRangeAddress[] regions = {CellRangeAddress.valueOf("A1:A3")};
sheetCF.addConditionalFormatting(regions, cfRules);
FileOutputStream fileOut = new FileOutputStream("ConditionalFormattingIconSet.xlsx");
workbook.write(fileOut);
fileOut.close();
} catch (IOException ioex) {
}
}
}
Looks like:
In my vaadin 7 application I have a CSSLayout that contains a Tabsheet. The Tabsheet contains a horizontalLayout. The HorizontalLayout contains a Table.
The table have a varying number of columns (between 3 and 20, changes upon request).
I want this table to occupy all available space both horizontally and vertically.
Vertically however the table should not extend beyond the the screen. So in case of having more rows than it can display the table should have a vertical scrollbar. (That is the case if I set the number of rows in table.setPageLength(), however I want to achieve this without setting explicit rownumbers, because I want the table to occupy all available space regardless of screensize, etc...)
Horizontally I also want a scrollbar if there are more columns then we have space for.
If I leave everything (csslayout, tabsheet, horizontallayout, table) default, I get the scrollbars, but I get a lot of space unused.
If I use setSizeFull() on tabsheet, horizontallayout, table then I get no unused space, however I lose the horizontal scrollbar and I can't ever reach end of the table with the vertical scrollbar.
Any help is appreciated.
EDIT -- UPDATE -- EDIT -- UPDATE --EDIT -- UPDATE --EDIT -- UPDATE
Here is a sample code. On my screen it's impossible to scroll down to the last row of the table. (and equally impossible to use the horizontal scrollbar)
#Override
protected void init(#SuppressWarnings("unused") VaadinRequest request) {
CssLayout css = new CssLayout();
HorizontalLayout upper = new HorizontalLayout();
OptionGroup first = new OptionGroup();
first.addItem("AAA");
first.addItem("BBB");
first.addItem("CCC");
first.addItem("DDD");
first.addItem("EEE");
first.addItem("Whatever");
upper.addComponent(first);
css.addComponent(upper);
HorizontalLayout hl = new HorizontalLayout();
hl.setMargin(true);
hl.setSpacing(true);
IndexedContainer c = new IndexedContainer();
for (int i = 0; i < 40; i++)
c.addContainerProperty("name" + i, String.class, "name" + i);
Table table = new Table("Test table", c);
for (int i = 0; i < 100; i++) {
Integer id = (Integer) c.addItem();
c.getItem(id).getItemProperty("name0").setValue(String.valueOf(i));
}
hl.addComponent(table);
TabSheet tab = new TabSheet();
tab.addTab(hl, "Table");
css.addComponent(tab);
hl.setSizeFull();
table.setSizeFull();
tab.setSizeFull();
css.setSizeFull();
setContent(css);
}
Maybe you don't set the size full on the css layout or maybe there are some trouble with styles.
It's better posting some code in questions like Why my code dosen't work?. However I wrote a simple test following your description and work as expected.
Edit
Try with VerticalLayout instead CssLayout
public class TestTableApp extends UI {
#Override
protected void init(VaadinRequest request) {
VerticalLayout css = new VerticalLayout();
HorizontalLayout upper = new HorizontalLayout();
OptionGroup first = new OptionGroup();
first.addItem("AAA");
first.addItem("BBB");
first.addItem("CCC");
first.addItem("DDD");
first.addItem("EEE");
first.addItem("Whatever");
upper.addComponent(first);
css.addComponent(upper);
HorizontalLayout hl = new HorizontalLayout();
hl.setMargin(true);
hl.setSpacing(true);
IndexedContainer c = new IndexedContainer();
for (int i = 0; i < 40; i++)
c.addContainerProperty("name" + i, String.class, "name" + i);
Table table = new Table("Test table", c);
for (int i = 0; i < 100; i++) {
Integer id = (Integer) c.addItem();
c.getItem(id).getItemProperty("name0").setValue(String.valueOf(i));
}
hl.addComponent(table);
TabSheet tab = new TabSheet();
tab.addTab(hl, "Table");
css.addComponent(tab);
hl.setSizeFull();
tab.setSizeFull();
table.setSizeFull();
css.setSizeFull();
// this do the trick
css.setExpandRatio(upper, 0);
css.setExpandRatio(tab, 1);
setContent(css);
}
}
In libgdx I have a TiledMap that I fill with different Cells:
cell.setTile(new StaticTiledMapTile(reg1));
cell.setTile(new StaticTiledMapTile(reg2));
cell.setTile(new StaticTiledMapTile(reg...));
where reg is a texture region.
I render with:
render = new OrthogonalTiledMapRenderer(map);
render.setView(cam);
render.render();
Throughout the game, the number of columns, number of rows and size of the cells will vary, so they must remain dynamic.
Now, around this TiledMap, I want to add a rounded border. Below I am showing some examples in png of how I am planning to do it : from left to right, first is a top border, then a top-right corner, then a right border. Each of these png files has square dimensions.
What I want to achieve below, here is a zoom to the top right corner of the TiledMap:
I am planning to use these pngs as TextureRegions that I can set as cells in my TiledMap, something like that:
for (int x = 0; x < numcol+2; x++) {
for (int y = 0; y < numrow+2; y++) {
Cell cell = new Cell();
if (y==numrow+1) {
cell.setTile(new StaticTiledMapTile(b_mid_top));
}
if (y==0) {
cell.setTile(new StaticTiledMapTile(b_mid_bottom));
}
etc.
I am having multiple issues with the dimension of the pngs: as I mentioned, the size of the cells may vary throughout the game. To my knowledge there is no way to resize a cell or a textureregion from a png as I would need.
So I could use Image, resize them dynamically, add them as actors to a stage and draw the stage, but I fear I might loose the benefit of using a TiledMap. Also, I would have to deal with stage coordinates on the one hand and TiledMap coordinates on the other and it doesn't sound the best approach.
So I am a bit lost!
What is the best approach to draw my border around my TiledMap?
I am ready to abandon any of my current ideas for a better one. I am not very experienced with Libgdx so sorry if I have done some silly mistake.
I think the idea is good. In case the tilesize changes the bordersize changes too. You can't create a different sized tile as frame around it. In case you want to create always the same frame, you can use a simple Ninepatch with the size of the Map.
create something like this:
NinePatch p = new NinePatch(texture, 5, 5, 5, 5); // the edge sizes are 5px here.
Inside of the render method you draw it at the size of the tilemap. you can optain the sizes from the Map object:
p.draw(batch, 0, 0, tilesize*tilecountx, tilesize*tilecounty);
If you do not liket his idea you can go for the second version. Create a new TiledMap with the boarder as tiles you need to copy the whole Tilemap with an offset of 1 tile (since you need to have 1 tile space) and create a new tilemap with 2 rows and cols more.
Should look for example like this:
map = new TiledMap(); // the map with the bordercells
MapLayers layers = map.getLayers();
for (int l = 0; l < map1.getLayers().getCount(); l++) {
// create a new layer which is bigger
TiledMapTileLayer newlayer = new TiledMapTileLayer(
((TiledMapTileLayer) map1.getLayers().get(0)).getWidth() + 2,
((TiledMapTileLayer) map1.getLayers().get(0)).getHeight() + 2,
(int) ((TiledMapTileLayer) map1.getLayers().get(0))
.getTileWidth(), (int) ((TiledMapTileLayer) map1
.getLayers().get(0)).getTileHeight());
// now add the cells here
for (int x = 0; x < newlayer.getWidth(); x++) {
for (int y = 0; y < newlayer.getHeight(); y++) {
//add the right tile regions here!
if(x == 0 && y == 0){
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(first edge));
newlayer.setCell(x, y, cell);
continue;
}
if(x == newlayer.getWidth()-1 && y == 0){
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(second edge));
newlayer.setCell(x, y, cell);
continue;
}
if(x == 0 && y == newlayer.getHeight()-1){
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(third edge));
newlayer.setCell(x, y, cell);
continue;
}
if(x == newlayer.getWidth()-1 && y == newlayer.getHeight()-1){
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(fourth edge));
newlayer.setCell(x, y, cell);
continue;
}
if(x == 0){
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(textureregion for bottom here));
newlayer.setCell(x, y, cell);
continue;
}
if(y == 0){
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(textureregion for first col));
newlayer.setCell(x, y, cell);
continue;
}
if(x == newlayer.getWidth()-1){
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(textureregion for toprow));
newlayer.setCell(x, y, cell);
continue;
}
if(y == newlayer.getHeight()-1){
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(textureregion for last col));
newlayer.setCell(x, y, cell);
continue;
}
//last but not least if none of this fit add the tile from the old map
//dont forget the offsett
newlayer.setCell(x, y, ((TiledMapTileLayer)map1.getLayers().get(l)).getCell(x-1, y-1)); //map1 is the original map without the borders
}
}
layers.add(newlayer);
}
If you really have different tilesizes i would just add an Bordertexture for every tilesize you have in case you are using the TiledMap version. If you like to resize a Texture take a Sprite for it. A Sprite offers the .setSize(w,h) and also extends the TextureRegion. To create a Static TiledMapTile you can also add the Sprite as Texture. So if you take the idea use a Sprite and size it to the tile size before you create the StaticTiledMapTile.