eclipse.platform.swt
eclipse.platform.swt copied to clipboard
Client Area is reported wrong when adding the first tab to a Tabfolder
Today I debugged some issues with tab folder and found the following quite annoying behavior (linux/gtk):
If one has an empty tab folder and adds the first tab to it, the client are is reported as 1x1 pixel right after that call. This leads to the tab appear to be "empty" or distorted depending on the widget it shows.
Query for the size in an async execution or when adding another tab always reports the correct size.
Here is a snippet to reproduce:
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
/*
* TabFolder example snippet: create a tab folder (six pages)
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class Snippet76a {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Snippet 76");
shell.setLayout(new GridLayout());
Button add = new Button(shell, SWT.PUSH);
add.setText("Add a tab");
final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
add.addSelectionListener(new SelectionListener() {
int i = 1;
@Override
public void widgetSelected(SelectionEvent e) {
System.out.println("The Client Area before adding a tab is: " + tabFolder.getClientArea());
TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
int j = i++;
tabItem.setText("Tab " + j);
Label label = new Label(tabFolder, SWT.NONE);
label.setText("Text inside the tab " + j);
tabItem.setControl(label);
System.out.println("The Client Area after ADDING a tab is: " + tabFolder.getClientArea());
display.asyncExec(() -> {
System.out.println("The Client Area after ASYNC is: " + tabFolder.getClientArea());
});
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
shell.setSize(400, 500);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Here is how it looks like:
https://github.com/eclipse-platform/eclipse.platform.swt/assets/1331477/5b90baa8-8c27-4b93-b289-0dff84655c85
As one can see the label is only visible after resizing the tab.