Skip to content

Commit ed79326

Browse files
author
jossonsmith
committed
Fixed a bug that Snippet106 adding table column fails.
1 parent 78879d9 commit ed79326

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Table.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,18 +1025,20 @@ void createItem (TableColumn column, int index) {
10251025
for (int i = 0; i < items.length; i++) {
10261026
Element dataTD = document.createElement("TD");
10271027
items[i].handle.insertBefore(dataTD, items[i].handle.childNodes[index]);
1028+
Element el = document.createElement("DIV");
1029+
dataTD.appendChild(el);
1030+
el.className = "table-item-cell-default";
1031+
Element text = document.createElement("DIV");
1032+
el.appendChild(text);
1033+
text.className = "table-item-cell-text-default";
10281034
for (int j = items[i].strings.length; j > index; j--) {
10291035
items[i].strings[j] = items[i].strings[j - 1];
10301036
}
10311037
items[i].strings[index] = "";
10321038
}
10331039
}
10341040
if (theadTD.childNodes != null) {
1035-
for (int i = 0; i < theadTD.childNodes.length; i++) {
1036-
if (theadTD.childNodes[i] != null) {
1037-
theadTD.removeChild(theadTD.childNodes[i]);
1038-
}
1039-
}
1041+
OS.clearChildren(theadTD);
10401042
}
10411043
theadTD.appendChild(document.createTextNode(column.getText()));
10421044
theadTD.style.margin = "0";

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/TableItem.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public TableItem (Table parent, int style, int index) {
123123
}
124124

125125
private void configureItem() {
126-
if((parent.style & SWT.CHECK) != 0){
126+
if((parent.style & SWT.CHECK) != 0 && check != null){
127127
check.onclick = new RunnableCompatibility() {
128128
public void run() {
129129
Event e = new Event();
@@ -770,7 +770,9 @@ public void setChecked (boolean checked) {
770770

771771
void setChecked (boolean checked, boolean notify) {
772772
this.checked = checked;
773-
this.check.checked = this.checked;
773+
if (this.check != null) {
774+
this.check.checked = this.checked;
775+
}
774776
if (notify) {
775777
Event event = new Event();
776778
event.item = this;
@@ -1166,7 +1168,7 @@ public void setText (int index, String string) {
11661168
int elementIndex = ((parent.style & SWT.CHECK) != 0 && index == 0)? 1 : 0;
11671169
Element text = handle.childNodes[index].childNodes[0].childNodes[elementIndex];
11681170
// Element[] children = text.childNodes;
1169-
text.innerHTML = "<div class=\"table-item-cell-text-default\">" + string + "</div>";
1171+
text.innerHTML = string;
11701172

11711173
int[] columnMaxWidth = parent.columnMaxWidth;
11721174
int width = OS.getContainerWidth(text.parentNode);
@@ -1334,7 +1336,9 @@ boolean isSelected(){
13341336

13351337
public void enableWidget(boolean enabled) {
13361338
this.handle.disabled = !enabled;
1337-
this.check.disabled = !enabled;
1339+
if (this.check != null) {
1340+
this.check.disabled = !enabled;
1341+
}
13381342
}
13391343

13401344
}

0 commit comments

Comments
 (0)