I have the following problem:
I'm using SWT to create a GUI for my application. I have a TabFolder in which I add several TabItems and in each of those I create a ScrolledComposite that holds some content.
The TabFolder is displaying fine, however the ScrolledComposite in the TabFolder does only show it's content in the first TabItem. All other ScrolledComposites are visible themselves just fine but their content is invisible.
Here is a little code snippet that demonstrates what I am referring to:
Display display = new Display();
Shell topShell = new Shell(display);
topShell.setSize(800, 800);
topShell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
topShell.setLayout(new FillLayout());
TabFolder folder = new TabFolder(topShell, SWT.NONE);
for (int i = 0; i < 5; i++) {
TabItem item = new TabItem(folder, SWT.NONE);
item.setText("Item " + i);
ScrolledComposite scroller = new ScrolledComposite(folder,
SWT.H_SCROLL | SWT.V_SCROLL );
scroller.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
Composite content = new Composite(scroller, SWT.NONE);
content.setBackground(display.getSystemColor(SWT.COLOR_RED));
scroller.setContent(content);
scroller.setExpandHorizontal(true);
scroller.setExpandVertical(true);
item.setControl(scroller);
}
topShell.setVisible(true);
while (!topShell.isDisposed()) {
display.readAndDispatch();
}
You can tell that the content is being displayed if the area is painted red. If the content is invisible the area is blue (the background of the ScrolledComposite)
I'm not sure if that matters but this occurs on Linux Mint 18 and it appears to only happen within GTK 3 (in 2 it works just fine)
After quite some time I tracked the issue down to the following:
It turned out that the problem was that the "missing" content had a size of zero, because the layouting doesn't set the size of those.
In my case it could be fixed by removing the SWT.V_SCROLL and the SWT.H_SCROLL style constants from the ScrolledComposite. Therefore the above code written as following works as expected.
Display display = new Display();
Shell topShell = new Shell(display);
topShell.setSize(800, 800);
topShell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
topShell.setLayout(new FillLayout());
TabFolder folder = new TabFolder(topShell, SWT.NONE);
for (int i = 0; i < 5; i++) {
TabItem item = new TabItem(folder, SWT.NONE);
item.setText("Item " + i);
ScrolledComposite scroller = new ScrolledComposite(folder,
SWT.NONE);
scroller.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
Composite content = new Composite(scroller, SWT.NONE);
content.setBackground(display.getSystemColor(SWT.COLOR_RED));
scroller.setContent(content);
scroller.setExpandHorizontal(true);
scroller.setExpandVertical(true);
item.setControl(scroller);
}
topShell.setVisible(true);
while (!topShell.isDisposed()) {
display.readAndDispatch();
}
Although that causes all content to be properly sized it completely removes the ScrollBars of the ScrolledComposite which somehow is not what you want from a ScrolledComposite.
Does anyone know how to fix that or whether that is a bug (that might have been fixed in newer SWT versions)?
I've fixed bugs related to this a few months ago.
Can you try latest SWT master?
http://download.eclipse.org/eclipse/downloads/
Related
I'm building a plugin for eclipse and have the following code to put a tabfolder in my view:
private void constructViewWindow(Composite parent){
final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
terminologyTab = new TabItem(tabFolder, SWT.NONE);
grammarTab = new TabItem(tabFolder, SWT.NONE);
styleTab = new TabItem(tabFolder, SWT.NONE);
xmlTab = new TabItem(tabFolder, SWT.NONE);
terminologyTable = new Table(tabFolder, SWT.BORDER);
grammarTable = new Table(tabFolder, SWT.BORDER);
styleTable = new Table(tabFolder, SWT.BORDER);
xmlTable = new Table(tabFolder, SWT.BORDER);
addTableColumns(terminologyTable);
addTableColumns(grammarTable);
addTableColumns(styleTable);
addTableColumns(xmlTable);
terminologyTab.setControl(terminologyTable);
grammarTab.setControl(grammarTable);
styleTab.setControl(styleTable);
xmlTab.setControl(xmlTable);
}
which results in the following window:
which is very nice. But I now want to add a description/some additional information to this, something that ends up in the same spot as the '0 items' text in the Tasks view:
Since I'm not sure what this would be called, googling is a bit difficult (e.g. I've tried "add header to table", but a header is obviously something else. "Description" didn't really do the trick either). I guess one could find this in the eclipse source code somewhere, but as I'm new to Java, and diving in the eclipse sources and finding what I need will take quite some time (at least for me), anyone any ideas on how to add this additional line of text above my TabFolder?
Just add a Label to the composite before the tab folder.
private void constructViewWindow(Composite parent){
label = new Label(parent, SWT.LEFT);
// TODO set layout on the layout
label.setText("0 items");
final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
You may need to set Layout Data on the label to make sure it is wide enough for the text.
Another way is to use the ViewForm class which lets you put controls at the corners of the page.
I want to manage the position of component in GUI by easily drag and drop them at design page of Eclipse. This is the GUI I see in design page.(Right click>Test/Preview)
I think after I finish rearrange the component in design page, it will look similar when I RUN the app. But, this GUI appear.
The different appearance make me very hard to adjust the component, for example the width of DAY 2, the height of Medication, DOB : and the green background.
Please let me know if there is any solution to this problem. Thanks.
You can use the GridLayout where each day is a column and the subjects(diagnosis, treatment and so on) are the rows. And you create a composite in each grid cell (like Day1 & diagnosis) which contains your buttons for this day and the subject.
[EDIT]
My suggested implementation is: (SWT.BORDER marks all cells of the toplevel grid)
GridLayout topLevelLayout = new GridLayout();
topLevelLayout.numColumns = 4;
parent.setLayout(topLevelLayout);
// head row
Label label = new Label(parent, SWT.BORDER);
label.setText("Activity");
label = new Label(parent, SWT.BORDER);
label.setText("Day 1");
label = new Label(parent, SWT.BORDER);
label.setText("Day 2");
label = new Label(parent, SWT.BORDER);
label.setText("Day 3");
// new row - first cell
label = new Label(parent, SWT.BORDER);
label.setText("Diagnosis");
// Day1 & Diagnosis
GridLayout cellLayout = new GridLayout();
cellLayout.numColumns = 2;
Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayout(cellLayout);
Button button = new Button(composite, SWT.NONE);
button.setText("ECG");
button = new Button(composite, SWT.NONE);
button.setText("Blood Pressure");
button = new Button(composite, SWT.NONE);
button.setText("Vital signs");
// other subjects of diagnosis at day 1...
// Day2 & Diagnosis
composite = new Composite(parent, SWT.BORDER);
// same layout like for day1 & diagnosis
composite.setLayout(cellLayout);
button = new Button(composite, SWT.NONE);
button.setText("ECG");
button = new Button(composite, SWT.NONE);
button.setText("Labs");
button = new Button(composite, SWT.NONE);
button.setText("Blood pressure");
// other subjects of diagnosis at day 2...
// Day3 & Diagnosis
composite = new Composite(parent, SWT.BORDER);
// same layout like for day1 & diagnosis
composite.setLayout(cellLayout);
button = new Button(composite, SWT.NONE);
button.setText("Stress Tests");
button = new Button(composite, SWT.NONE);
button.setText("Labs");
button = new Button(composite, SWT.NONE);
button.setText("Cardiac rhythm");
// other subjects of diagnosis at day 1...
label = new Label(parent, SWT.BORDER);
label.setText("Treatment");
Things like this happen with any designer. Usually they are an indicator of a location change occuring at runtime as the result of a dynamic parameter of some kind. Make sure that you having the correct padding on each of the buttons, and whatever you are using to contain the buttons in should be using a consistent spacing for each one. Also make sure that alignment within the containers is correct, and that both your buttons and the containers they are in are properly anchored.
I am creating a breadcrumb control in SWT which shows a bar at the top to search a location on the file system and a JFace table, using a TableViewer, below that bar to display the results i.e the folders and the files at the given location. The problem is once the data is loaded into the table and I try to maximize the window, the table collapses(sometimes disappears totally) leaving a empty space beneath it and making itself scroll-able. Below is the image before maximizing.
And this happens after maximizing the window.
What should be done to correct this? Here is my code for creating the viewer.
DirectoryViewer container = new DirectoryViewer(this, SWT.BORDER|SWT.V_SCROLL|SWT.FULL_SELECTION);
GridData conData = new GridData();
conData .horizontalAlignment = SWT.FILL;
conData.verticalAlignment = SWT.FILL;
conData .grabExcessHorizontalSpace = true;
conData.grabExcessVerticalSpace = true;
conData .horizontalSpan = 3;
container.getTable().setLayoutData(conData);
And the constructor of DirectoryViewer:
public DirectoryViewer(Composite parent, int style) {
super(parent, style);
Table table = getTable();
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData .horizontalSpan = 3;
table.setLayoutData(gridData);
createColumns();
table.setHeaderVisible(true);
setContentProvider(new ContentProvider());
}
i try to use an org.eclipse.jface.viewers.CheckboxTableViewer, as a component of a org.eclipse.jface.wizard.WizardPage. I created it this way:
public void createControl(Composite parent) {
composite = new Composite(parent, SWT.NULL);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
setControl(composite);
/* CheckboxTableViewer */
viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
final Table table = viewer.getTable();
GridData data1 = new GridData();
data1.grabExcessHorizontalSpace = true;
data1.grabExcessVerticalSpace = true;
data1.horizontalSpan = 2;
data1.horizontalAlignment = SWT.FILL;
data1.verticalAlignment = SWT.FILL;
table.setLayoutData(data1);
table.setHeaderVisible(true);
table.setLinesVisible(true);
checkboxColumn = new TableColumn(table, SWT.LEFT);
...
the content of the viewer is inserted dynamically by a contentprovider. Everything works fine on gnome. While testing this on windows 7 (64 and 32 bit also), i am not able to select any entries of that view. Mouseclicks just seems to have no impact on the view.
I added a mouselistener to the table, and the mouseUp-/Down event is fired, selectionChanged and doubleClick on the viewer is not fired. Anyone who can explain this behaviour to me?
thx in advance,
hage
(i already posted this question in the eclipse forum without any response yet: http://www.eclipse.org/forums/index.php/t/250953/ )
You have to add another style flag while creating the CheckboxTableViewer: SWT.FULL_SELECTION
viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);
You can now select rows in the table by a single clicking.
I am trying to add a scrollable area to my tabbed window. So far I have a CTabFolder in a shell. I have added 5 CTabItems to it and everything works as expected.
On one of my CTabItems the contents are too big to fit on the screen so I would like to be able to scroll. The contents is a collection of Groups each containing various widgets.
So the CTabFolder is created as follows:
CTabFolder tabs = new CTabFolder(shell, SWT.BORDER);
tabs.setSimple(false);
tabs.setUnselectedImageVisible(false);
tabs.setUnselectedCloseVisible(false);
tabs.setMinimizeVisible(false);
tabs.setMaximizeVisible(false);
FormData tabsLayoutData = new FormData();
tabsLayoutData.top = new FormAttachment(0, 5);
tabsLayoutData.left = new FormAttachment(0, 5);
tabsLayoutData.bottom = new FormAttachment(92, 0);
tabsLayoutData.right = new FormAttachment(100, -5);
tabs.setLayoutData(tabsLayoutData);
Then the CTabItem:
CTabItem tab = new CTabItem(tabs, SWT.NONE);
tab.setText("Role");
Then the contents:
Composite tabArea = new Composite(tabs, SWT.V_SCROLL);
tabArea.setLayout(new FormLayout());
tab.setControl(tabArea);
So the groups contained within the tab are created with tabArea as the parent and everything appears as you would expect. The problem is though that the vertical scroll bar is always present but doesn't seem to do anything. The contents are chopped off at the bottom of the tabArea composite.
Is there anything else I need to do to get the scrolling to work properly?
You need to use a ScrolledComposite. (Scroll down and find links to JavaDoc & snippets)
Here is code that should work in your situation:
ScrolledComposite scroller = new ScrolledComposite(tabs, SWT.BORDER | SWT.V_SCROLL);
Composite tabArea = new Composite(scroller, SWT.NONE);
scroller.setContent(tabArea);
// create some controls in TabArea and assign a layout to TabArea
scroller.setExpandVertical(true);
scroller.setExpandHorizontal(true);
scroller.setMinSize(tabArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
tab.setControl(scroller);