Community
Participate
Working Groups
Bugzilla – Bug 225933
First Table Column Justification Ignored
Last modified: 2008-07-28 15:06:48 EDT
The justification for the first column in a table is ignored. In the code below, I set the alignment to SWT.LEFT, but it seems to be SWT.CENTER at runtime. import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.layout.*; public class OSXColumnBug { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display, SWT.CLOSE); shell.setLayout(new RowLayout()); shell.setText("OS X First Column Justification Bug"); // move to strings property file Table table = new Table(shell, SWT.BORDER); table.setHeaderVisible(true); TableColumn tc1 = new TableColumn(table, SWT.CENTER); TableColumn tc2 = new TableColumn(table, SWT.CENTER); tc1.setText("Left? :("); tc1.setAlignment(SWT.LEFT); tc1.setWidth(80); tc2.setText("Left! :)"); tc2.setAlignment(SWT.LEFT); tc2.setWidth(80); shell.pack(); shell.open(); while(!shell.isDisposed()){ if(!display.readAndDispatch()) display.sleep(); } } }
Please ignore the code comment, it's irrelevant.
*** This bug has been marked as a duplicate of bug 151342 ***
All of the bugs involved with first column alignment are reported for Windows. In bug #151342, there is a mention that this is a "known platform limitation." In bug #16223, MSDN is quoted as saying that the alignment requests on the first column will be rejected on Windows. So, is this a platform limitation with Windows or with SWT?
It's a platform limitation in Windows. Since SWT is native, we can either try to work around it, or accept it. I haven't tried to work around it recently but from memory, there was hope. In the meantime, you can work around it in application code by creating a zero sized first column.
I don't think a workaround is necessary, at least for non-Windows platforms, since the limitation only exists in Windows. Can't we simply change the line in TableColumn.setAlignment() from if (index == -1 || index == 0) return; to if (index == -1) return; in the non-Windows source files for TableColumn, since they're separated by platform?
Can't do it. If we did, then you would write code that worked on some platforms and failed on others (Windows).
Am I right in concluding that this is a design decision to present a uniform level of functionality over all platforms rather than providing maximum functionality for each platform?
Wow, that's a strong statement. The design is to write portable native user interfaces with the correct behavior on each platform. When portable conflicts with native behavior, there is a choice between providing a hint and being different between platforms or enforcing consistent behavior (in this case, forcing Windows behavior on the other platforms. To be clear, other platform behavior has been force on Windows so don't get the impression that Windows always "wins"). We could honour the alignment on every platform except Windows and clear the alignment bit. Applications would then be able to detect that alignment failed on Windows and do something.
I'm sorry that came off strongly, I didn't mean to generalize from this specific case to the entire SWT project. I know you guys have a lot to handle without random snark in bug reports. I was trying to make sure I had the design philosophy correct. :) As it stands, it's intentionally broken on all platforms (and therefore a design feature rather than a bug), yet undocumented, which is where part of my concern lies. I would have thought that if a design decision was made to make the first column alignment behave a certain way, it would be in the javadocs (maybe people have been busy). I think providing an alignment hint would be much better than ignoring it on all platforms. As there are plenty of places in SWT where interface isn't guaranteed to be consistent over every platform, is it reasonable to even provide a mechanism for detecting the lack of alignment?
There are places and they are inconsistenly documented. I will document this one right now. * <p> * Note that due to a restriction on some platforms, the first column * is always left aligned. * </p>
Aww, so does that mean that you're not going to hint on OS X or GTK? (Also, on OS X, it's center-aligned)
Yes, I can't change this now (after API freeze) anyways. OS X needs to be fixed to be "wrong".
Created attachment 95725 [details] patch
fixed carbon to be "wrong" > 20080411
Well, on Linux, you cannot set the alignment of the first column using TableColumn.setAlignment(int), but if you give the alignment in the constructor it works!
Bogdan, please fix GTK to be "wrong" (consistent). When (if) we fix the issue in Windows, we will remove the restriction from the other platforms.
I think there are two ways of using SWT: 1. for cross platform UI 2. for native UI on a specific platform In the first case it makes sense to make it behave the same on all platforms. But if you want to use SWT as native java UI on a specific platform, then those "fixes" are annoying.
*** Bug 242181 has been marked as a duplicate of this bug. ***