java - Table renderer where there are 2 if statements -
i have table renderer makes row in table red depending on contents of column 11. works fine , code below:
tabler = new jtable(modelr) { @override public component preparerenderer(tablecellrenderer renderer, int row, int column) { component c = super.preparerenderer(renderer, row, column); font myfont = new font("arial",font.plain,10); font myfont1 = new font("arial", font.bold,10); int rowmodelid = convertrowindextomodel( row ); if (!isrowselected(row)) { if (tabler.getcolumncount() >= 0) { string type = (string) getmodel().getvalueat(rowmodelid, 11); c.setbackground("0.0".equals(type) ? color.red : color.white); c.setforeground("0.0".equals(type) ? color.white : color.black); c.setfont("0.0".equals(type) ? myfont1: myfont); } } return c; }
i want additionally implement same thing column 12, if criteria met, in case "u" particular row yellow. attempt below no colour appears @ in table. in addition happen if column 11, , column 12 coloured --what happen in scenario?
here attempted go:
tabler = new jtable(modelr) { @override public component preparerenderer(tablecellrenderer renderer, int row, int column) { component c = super.preparerenderer(renderer, row, column); font myfont = new font("arial",font.plain,10); font myfont1 = new font("arial", font.bold,10); int rowmodelid = convertrowindextomodel( row ); int rowmodelid1 = convertrowindextomodel( row ); if (!isrowselected(row)) { if (tabler.getcolumncount() >= 0) { string type = (string) getmodel().getvalueat(rowmodelid, 11); c.setbackground("0.0".equals(type) ? color.red : color.white); c.setforeground("0.0".equals(type) ? color.white : color.black); c.setfont("0.0".equals(type) ? myfont1: myfont); } if (tabler.getcolumncount() >= 0) { string type = (string) getmodel().getvalueat(rowmodelid1, 12); c.setbackground("u".equals(type) ? color.yellow : color.white); c.setforeground("u".equals(type) ? color.white : color.black); c.setfont("u".equals(type) ? myfont1: myfont); } } return c; }
tabler = new jtable(modelr) { @override public component preparerenderer(tablecellrenderer renderer, int row, int column) { component c = super.preparerenderer(renderer, row, column); font myfont = new font("arial",font.plain,10); font myfont1 = new font("arial", font.bold,10); int rowmodelid = convertrowindextomodel( row ); int rowmodelid1 = convertrowindextomodel( row ); if (!isrowselected(row)) { if (tabler.getcolumncount() >= 0) { string type = (string) getmodel().getvalueat(rowmodelid1, 12); if("u".equals(type)) { c.setbackground(color.yellow); c.setforeground(color.white); c.setfont(myfont1); return c; } type = (string) getmodel().getvalueat(rowmodelid, 11); if("0.0".equals(type)) { c.setbackground(color.red); c.setforeground(color.white); c.setfont(myfont1); return c; } } c.setbackground(color.white); c.setforeground(color.black); c.setfont(myfont); } return c; } }
here go, hope solves it
Comments
Post a Comment