java - SWT table with custom editors gets messed up on resizing -
I use a table to display 5 columns. 3 and 5th include custom widgets and the fourth one is editable. The window looks fine on the first look:
However, if I change a bit of window size, the widgets inside the table are in the wrong place.
View the table again For it is enough to set the focus.
Here is a MCVE that reproduces this problem:
import java.util.ArrayList; Import org.eclipse.jface.window.ApplicationWindow; Import org.eclipse.swt.SWT; Import org.eclipse.swt.custom.TableEditor; Import org.eclipse.swt.layout.FillLayout; Import org.eclipse.swt.layout.GridLayout; Import org.eclipse.swt.widgets.Button; Import org.eclipse.swt.widgets.Combo; Import org.eclipse.swt.widgets.Composite; Import org.eclipse.swt.widgets.Control; Import org.eclipse.swt.widgets.Display; Import org.eclipse.swt.widgets.Event; Import org.eclipse.swt.widgets.Listener; Import org.eclipse.swt.widgets.Table; Import org.eclipse.swt.widgets.TableColumn; Import org.eclipse.swt.widgets.TableItem; Public Class Tablet ApplicationWindow {Private Table Tables; ArrayList & LT; TableDescription & gt; TableDiscription = new ArrayLite & Lt; Tabletest.TableDiscription & gt; (); Public Class Table Description {Name of Private String; Private string type; Public table description (string name, string type) {this.name = name; This.Type = type; } Public string getName () {return name; } Public string getType () {return type; }} Public Tablet () {Super} (empty); // Test Data Table Description.ad (New Table Description ("Rev_ID", "Bonnit")); TableDescriptions.add (new table description ("Entity_Name", "varchar")); } @ Override Protected Control Making Machinery (Composite Parent) {Composite Container = New Composite (Parent, SWT.NONE); Container.Settleout (newFillout (SWT.HORIZONTAL)); Table = new table (container, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); Table.setLinesVisible (true); Table.setHeaderVisible (true); Grid layout layout = new gridlate (); Table.setLayout (layout); String [] titles = {"column name", "column type", "visibility", "GUI name", "GUI type"}; For (int i = 0; i and lieutenant; title.lamp; i ++) {last table column column = new table column (table, SWT.NONE); Column.setText (titles [i]); } Int [] columnsWidths = new int [] {100, 100, 50, 100, 95}; (Description for Table Description Table: Table Description) {Table Item Items = New Tablet (Table, SWT.NONE); Item.setText (0, tableDescription.getName ()); Item.setText (1, tabledesign .getType ()); Item.setText (3, tableDescription.getName (). ReplaceAll ("_", "")); } (Int i = 0; i & lt; table.getColumnCount (); i ++) {table.getColumn (i) .setWidth (Column Widths [i]); } // The listener which sets the row heights // Adds editors to the other program, place them according to the new cell sizes. // So it removes itself table.Ed Listener (SWT.MeasureItem, New Listener) {Boolean RowHyetset, Public Zero Dealer Event (Event Event) {If (! LineHighसेट) {rowHeightSet = true; event.height = 25;} and {addEditors (table description); Table RemoveListener (SWT.MeasureItem, this);}}}); Return container; } Private Zero addEditors (ArrayList & lt; TableDescription & gt; Table Description) {for (int i = 0; i & lt; tableDescriptions.size (); i ++) {table item item = table.getItem (i); Table edit editor = new table editor (table); Button check button = new button (table, SWT.CHECK); CheckButton.setSelection (true); CheckButton.pack (); Editor. Minimum Width = checkButton.getSize () X; Editor. HirizontalAlignment = SWT.CENTER; Editor. Sender (check button, item, 2); Item.setData ("CheckButton Editor", Editor); Editor = new table editor (table); Combo box = new combo (table, SWT.READ_ONLY); Box.pack (); Editor. Minimum Width = box.getSize () X; Editor. HirizontalAlignment = SWT.LEFT; Editor.setting editor (box, item, 4); Item.setData ("comboBoxEditor", editor); }} Public static zero main (string rule []) {try {TableTest window = New TableTest (); Window.setBlockOnOpen (true); Window.open (); Display.getCurrent () Settlement () .; } Hold (exception e) {e.printStackTrace (); }}} How can this issue be solved, any thoughts?
Hey, got a solution from the accident :) I was looking at your code and wondering: Why does it apply grid layout to the table? " Tired it out and TADA! Does it work.
Then just remove these two lines and you should be OK:
Grid layout layout = new grid layout (); Table.setLayout (layout);
Comments
Post a Comment