Bug 225933 - First Table Column Justification Ignored
First Table Column Justification Ignored
Status: RESOLVED FIXED
Product: Platform
Classification: Eclipse
Component: SWT
3.3.1
PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
: 3.4 M7
Assigned To: Kevin Barnes CLA Friend
:
: 242181 (view as bug list)
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2008-04-07 01:38 EDT by Michael Shapiro CLA Friend
Modified: 2008-07-28 15:06 EDT (History)
7 users (show)

See Also:


Attachments
patch (1.91 KB, patch)
2008-04-11 14:08 EDT, Kevin Barnes CLA Friend
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Shapiro CLA Friend 2008-04-07 01:38:56 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();
                }
        }
}
Comment 1 Michael Shapiro CLA Friend 2008-04-08 13:01:25 EDT
Please ignore the code comment, it's irrelevant.
Comment 2 Kevin Barnes CLA Friend 2008-04-09 13:35:32 EDT

*** This bug has been marked as a duplicate of bug 151342 ***
Comment 3 Michael Shapiro CLA Friend 2008-04-09 18:24:54 EDT
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?
Comment 4 Steve Northover CLA Friend 2008-04-10 10:18:09 EDT
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.
Comment 5 Michael Shapiro CLA Friend 2008-04-10 10:43:23 EDT
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?
Comment 6 Steve Northover CLA Friend 2008-04-10 10:58:05 EDT
Can't do it.  If we did, then you would write code that worked on some platforms and failed on others (Windows).
Comment 7 Michael Shapiro CLA Friend 2008-04-10 11:01:25 EDT
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?
Comment 8 Steve Northover CLA Friend 2008-04-10 11:24:15 EDT
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.
Comment 9 Michael Shapiro CLA Friend 2008-04-10 12:34:13 EDT
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?
Comment 10 Steve Northover CLA Friend 2008-04-10 13:18:55 EDT
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>
Comment 11 Michael Shapiro CLA Friend 2008-04-10 13:22:44 EDT
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)
Comment 12 Steve Northover CLA Friend 2008-04-10 13:31:12 EDT
Yes, I can't change this now (after API freeze) anyways.  OS X needs to be fixed to be "wrong".
Comment 13 Kevin Barnes CLA Friend 2008-04-11 14:08:20 EDT
Created attachment 95725 [details]
patch
Comment 14 Kevin Barnes CLA Friend 2008-04-11 14:10:23 EDT
fixed carbon to be "wrong" > 20080411
Comment 15 Michael Scharf CLA Friend 2008-07-10 09:03:10 EDT
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!


Comment 16 Steve Northover CLA Friend 2008-07-10 11:22:20 EDT
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.
Comment 17 Michael Scharf CLA Friend 2008-07-10 11:28:15 EDT
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.
Comment 18 Steve Northover CLA Friend 2008-07-28 15:06:48 EDT
*** Bug 242181 has been marked as a duplicate of this bug. ***