i have styledtext widget embedded table controls. however, once add measureitem listener adjust size of table cells, table appears @ top of styledtext widget first time scroll, remaining there until scroll way expected location.
is known issue? doing wrong?
code snippet:
import org.eclipse.swt.swt; import org.eclipse.swt.custom.paintobjectevent; import org.eclipse.swt.custom.paintobjectlistener; import org.eclipse.swt.custom.stylerange; import org.eclipse.swt.custom.styledtext; import org.eclipse.swt.graphics.glyphmetrics; import org.eclipse.swt.graphics.rectangle; import org.eclipse.swt.layout.filllayout; import org.eclipse.swt.widgets.display; import org.eclipse.swt.widgets.event; import org.eclipse.swt.widgets.listener; import org.eclipse.swt.widgets.shell; import org.eclipse.swt.widgets.table; import org.eclipse.swt.widgets.tablecolumn; import org.eclipse.swt.widgets.tableitem; public class jumpingtable { public static void main(string[] args) { // initialize gui display display = new display(); shell shell = new shell(display); // create editor styledtext styledtext = new styledtext(shell, swt.v_scroll); shell.setlayout(new filllayout()); // insert lots of text (int i=0; i<100; ++i) { styledtext.append("lorem ipsum\r\n"); } // create table table table = new table(styledtext, swt.none); table.setvisible(false); // *** prevents table jumping (int i=0; i<3; ++i) { tablecolumn column = new tablecolumn(table, swt.none); column.setwidth(100); } (int i=0; i<3; ++i) { tableitem row = new tableitem(table, swt.none); row.settext(new string[] {"a", "b", "c"}); } // place table int tableoffset = styledtext.getcharcount(); styledtext.append("\ufffc"); // object replacement code stylerange style = new stylerange(); style.start = tableoffset; style.length = 1; style.data = table; //table.pack(); table.setsize(300, 150); // accomodate measureitem's sizing rectangle rect = table.getbounds(); int ascent = 2*rect.height/3; int descent = rect.height - ascent; style.metrics = new glyphmetrics(ascent, descent, rect.width); styledtext.setstylerange(style); // draw table styledtext.addpaintobjectlistener(new paintobjectlistener() { @override public void paintobject(paintobjectevent event) { table table = (table) event.style.data; table.setvisible(true); int y = event.y + event.ascent - event.style.metrics.ascent; table.setlocation(event.x, y); } }); // adjust sizing table.addlistener(swt.measureitem, new listener() { @override public void handleevent(event event) { if (event.type == swt.measureitem) { event.width = 100; event.height = 50; } } }); // display gui shell.open(); while (!shell.isdisposed()) { if (!display.readanddispatch()) display.sleep(); } // clean display.dispose(); } }
i have no idea, why doing this, anyway..
your table isn't located appropriately after creation, , "sits" on base coordinates (0, 0). have locate table right place.
add line after styledtext.setstylerange(style);
, work need.
table.setlocation(styledtext.getlocationatoffset(styledtext.getcharcount()));
and it's not necessary, have line, can delete it..
table.setvisible(false); // *** prevents table jumping
Comments
Post a Comment