dazhi00 2013-12-13
控件和背景图片一样大小
import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.layout.RowData; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; 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 UsingImage { static Display display = Display.getDefault(); static Image backgroundImage = new Image(display, UsingImage.class .getResourceAsStream("270x320_note_background.png")); static Image image2 = new Image(display, UsingImage.class .getResourceAsStream("48x48_package_viewer.png")); public static void main(String[] args) { Shell shell = new Shell(display); shell.setSize(1000, 600); createNotePage(shell); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } backgroundImage.dispose(); display.dispose(); } private static void createNotePage(Shell shell) { int w = backgroundImage.getImageData().width; int h = backgroundImage.getImageData().height; Composite panel = new Composite(shell, SWT.NONE); panel.setSize(w, h); panel.setLayout(new FormLayout()); Composite topPanel = new Composite(panel, SWT.NONE); FormData formdata = new FormData(); formdata.left = new FormAttachment(0,5); formdata.right = new FormAttachment(100,-5); formdata.top = new FormAttachment(0,2); formdata.bottom = new FormAttachment(50, -10); topPanel.setLayoutData(formdata); Composite bottomPanel = new Composite(panel, SWT.NONE); FormData buttonDataA = new FormData(); buttonDataA.left = new FormAttachment(0,5); buttonDataA.right = new FormAttachment(100,-5); buttonDataA.top = new FormAttachment(50,24); buttonDataA.bottom = new FormAttachment(100, -12); bottomPanel.setLayoutData(buttonDataA); Label backgroudLable = new Label(panel, SWT.NONE); backgroudLable.setImage(backgroundImage); FormData data1 = new FormData(); backgroudLable.setLayoutData(data1); createNoteArea(topPanel, bottomPanel); panel.layout(); } private static void createNoteArea(Composite topPanel, Composite bottomPanel) { createTopPanelArea(topPanel); createBottomPanelArea(bottomPanel); } private static void createBottomPanelArea(Composite panel) { panel.setLayout(new RowLayout()); for(int i=0; i<6; i++) { Label lable = new Label(panel, SWT.NONE); lable.setImage(image2); } } private static void createTopPanelArea(Composite panel) { panel.setLayout(new RowLayout()); Table table = creatResourceTable(panel); table.setLayoutData(new RowData(-1, 90)); table = creatClkTable(panel); table.setLayoutData(new RowData(-1, 25)); } public static Table creatResourceTable(Composite panel) { Table table = new Table(panel, SWT.NONE | SWT.FULL_SELECTION | SWT.NO_SCROLL); table.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); table.setHeaderVisible(false); String[] columns = new String[]{"name","used","total","ratio"}; for(String name : columns) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(name); column.setWidth(58); } String[] input = new String[]{"LUT", "100", "1200", "50%"}; TableItem item = new TableItem(table, SWT.NONE); for(int i=0; i < input.length; i++) { item.setText(i, input[i]); } input = new String[]{"FF", "100", "1200", "50%"}; item = new TableItem(table, SWT.NONE); for(int i=0; i < input.length; i++) { item.setText(i, input[i]); } input = new String[]{"BRAM", "1", "10", "10%"}; item = new TableItem(table, SWT.NONE); for(int i=0; i < input.length; i++) { item.setText(i, input[i]); } input = new String[]{"MULT", "0", "10", "0%"}; item = new TableItem(table, SWT.NONE); for(int i=0; i < input.length; i++) { item.setText(i, input[i]); } return table; } public static Table creatClkTable(Composite panel) { Table table = new Table(panel, SWT.NONE | SWT.FULL_SELECTION); table.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); table.setHeaderVisible(false); String[] columns = new String[]{"clkName", "hz"}; for(String name : columns) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(name); column.setWidth(116); } String[] input = new String[]{"clk_pad_i", "123.1 MHZ"}; TableItem item = new TableItem(table, SWT.NONE); for(int i=0; i < input.length; i++) { item.setText(i, input[i]); } input = new String[]{"bit_clk_i", "102.9 MHZ"}; item = new TableItem(table, SWT.NONE); for(int i=0; i < input.length; i++) { item.setText(i, input[i]); } return table; } }