Results 1 to 1 of 1
Thread: How to setBounds for a tableItem
- 06-25-2010, 02:53 PM #1
Member
- Join Date
- May 2010
- Posts
- 7
- Rep Power
- 0
How to setBounds for a tableItem
Hi,
I have a problem with TableColumn and TableItem objects.
I want to create a table and in column header insert an image. The problem is that the image is not displayed from left side of the header, always there remains a few pixels free and only after that is displayed the image.
I have investigated a little this problem and seems that the same problem is for any TableItem. When I call the getBounds() method it return me x = 6 and I don't understand why. I suppose that the same problem is with the column header. How can I display the image from column header and the items exactly from the left side of the column?(without any margin or border or what anything else can represent that 6 pixels)
Here is my code :
Thanks in advance!!Java Code:import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; 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 TableTest { private Shell sShell = null; private Composite composite = null; private Table table = null; /** * This method initializes composite * */ private void createComposite() { composite = new Composite(sShell, SWT.NONE); composite.setLayout(new FillLayout()); table = new Table(composite, SWT.NONE); table.setHeaderVisible(true); table.setLinesVisible(true); Image img = new Image(table.getDisplay(), "res/image.png"); TableColumn col = new TableColumn(table, SWT.NONE); col.setImage(img); col.setWidth(200); col.setAlignment(SWT.LEFT); System.out.println(col.getAlignment()); col.pack(); for (int i = 0; i < 10; i++) { TableItem item = new TableItem(table, SWT.NO_REDRAW_RESIZE); item.setText("item " + i); Rectangle r = item.getTextBounds(0); System.out.println("x = " + r.x); } table.pack(); } /** * @param args */ public static void main(String[] args) { Display display = Display.getDefault(); TableTest thisClass = new TableTest(); thisClass.createSShell(); thisClass.sShell.open(); while (!thisClass.sShell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } /** * This method initializes sShell */ private void createSShell() { sShell = new Shell(); sShell.setText("Shell"); createComposite(); sShell.setSize(new Point(300, 200)); sShell.setLayout(new FillLayout()); } }
Similar Threads
-
control setLocation setBounds
By xna in forum New To JavaReplies: 3Last Post: 11-11-2009, 04:29 AM -
Positioning using setBounds
By thayalan in forum AWT / SwingReplies: 4Last Post: 04-28-2009, 01:59 AM -
Using setBounds (x.y,width,height) constructor
By hitmen in forum AWT / SwingReplies: 3Last Post: 03-06-2009, 12:12 PM -
Problem here guys: Set location or setBounds
By themburu in forum New To JavaReplies: 3Last Post: 06-03-2008, 07:19 PM


LinkBack URL
About LinkBacks

Bookmarks