swt add widgets towards right in formLayout - java

Here is my code:
Composite outer = new Composite(parent, SWT.BORDER);
outer.setBackground(new Color(null, 207, 255, 206)); // Green
FormLayout formLayout = new FormLayout();
formLayout.marginHeight = 5;
formLayout.marginWidth = 5;
formLayout.spacing = 5;
outer.setLayout(formLayout);
//TOP
Composite Top = new Composite(outer, SWT.BORDER);
Top.setLayout(new GridLayout());
Top.setBackground(new Color(null, 232, 223, 255)); // Blue
FormData fData = new FormData();
fData.top = new FormAttachment(0);
fData.left = new FormAttachment(0);
fData.right = new FormAttachment(100); // Locks on 10% of the view
fData.bottom = new FormAttachment(20);
Top.setLayoutData(fData);
//BOTTOM
Composite Bottom = new Composite(outer, SWT.BORDER);
Bottom.setLayout(fillLayout);
Bottom.setBackground(new Color(null, 255, 235, 223)); // Orange
fData = new FormData();
fData.top = new FormAttachment(20);
fData.left = new FormAttachment(0);
fData.right = new FormAttachment(100);
fData.bottom = new FormAttachment(100);
Bottom.setLayoutData(fData);
I just wanted to add widgets for example label images to the right of the "TOP" composite layout. Since i am new to swt, am facing difficulty to align all the label to right of it. How could i achieve this ?

If want to place another width to the right of top you first need to advise top to not occupy 100% of the available space, for example only half of the space:
FormData formData = new FormData();
formData.right = new FormAttachment( 50 );
Or you can leave formData.right unspecified (i.e. null) so that the widget will use its preferred width.
Once there is room for another widget, you can right-attach one like so:
Composite right = new Composite( outer, SWT.BORDER );
right.setBackground( display.getSystemColor( SWT.COLOR_YELLOW ) );
FormData rightFormData = new FormData();
rightFormData.top = new FormAttachment( top, 0, SWT.TOP );
rightFormData.left = new FormAttachment( top );
rightFormData.bottom = new FormAttachment( top, 0, SWT.BOTTOM );
right.setLayoutData( rightFormData );
The result will look like this:
To learn more about FormLayout and other layouts in SWT I recommend the
Understanding Layouts in SWT article. Though the article may seem outdated, Layouts in SWT haven't changed since then thus the contents of the article are still valid.
Once you are fluent with the FormLayout and look for a less verbose way to specify the positioning you might want to try this FormLayout helper.

Related

Intellij "Jar with dependencies" artifact results in misaligned JavaFX checkboxes

Left side of picture: It is when it is run directly from intellij
Right side of picture: Created fat jar (which is created by the feature called "Jar with dependencies") is run as double click from mouse
As you can see, Checkboxes are not aligned .Every component is created by code not from fxml...What can be the cause of this?
Edit:
First of all, width and height are fixed. Thus they will never change. I disabled Them Below you can find the code.
HBox row1 = new HBox(10);
//row1.setPadding();
Label nameLbl = new Label("Login Email");
nameLbl.setPrefWidth(DefaultValues.LABEL_WIDTH);
nameLbl.setPadding(new Insets(4,0,0,0));
txtEmail = new TextField();
txtEmail.setPrefSize(DefaultValues.TEXTAREA_WIDTH,20);
txtEmail.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(!newValue)
checkLicence();
});
row1.getChildren().addAll(nameLbl,txtEmail);
HBox row2 = new HBox(10);
Label passwordLbl = new Label("Password");
passwordLbl.setPrefWidth(DefaultValues.LABEL_WIDTH);
passwordLbl.setPadding(new Insets(4,0,0,0));
txtPassword = new PasswordField();
txtPassword.setPrefSize(DefaultValues.TEXTAREA_WIDTH,20);
row2.getChildren().add(passwordLbl);
row2.getChildren().add(txtPassword);
HBox row3 = new HBox(10);
//row1.setPadding();
Label refreshTime = new Label("Refresh Time");
refreshTime.setPrefWidth(DefaultValues.LABEL_WIDTH);
refreshTime.setPadding(new Insets(4,0,0,0));
txtRefreshTime = new TextField();
txtRefreshTime.setPrefSize(DefaultValues.TEXTAREA_WIDTH,20);
txtRefreshTime.setPromptText("Seconds");
txtRefreshTime.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.matches("\\d*")) {
txtRefreshTime.setText(newValue.replaceAll("[^\\d]", ""));
}
});
row3.getChildren().add(refreshTime);
row3.getChildren().add(txtRefreshTime);
HBox row3_1 = new HBox(10);
//row1.setPadding();
Label userCountLbl = new Label("User Count(for point calc.)");
userCountLbl.setPrefWidth(DefaultValues.LABEL_WIDTH);
userCountLbl.setPadding(new Insets(4,0,0,0));
txtUserCountForPointCalc = new TextField();
txtUserCountForPointCalc.setPrefSize(DefaultValues.TEXTAREA_WIDTH,20);
txtUserCountForPointCalc.setPromptText("Not very important");
txtUserCountForPointCalc.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.matches("\\d*")) {
txtUserCountForPointCalc.setText(newValue.replaceAll("[^\\d]", ""));
}
});
row3_1.getChildren().add(userCountLbl);
row3_1.getChildren().add(txtUserCountForPointCalc);
HBox row4 = new HBox(10);
//row1.setPadding();
Label showNotifications = new Label("Show Notifications");
showNotifications.setPrefWidth(DefaultValues.LABEL_WIDTH - 10);
showNotifications.setPadding(new Insets(4,0,0,0));
cbShowNotifications = new CheckBox();
cbShowNotifications.setPrefWidth(180);
Button btnClearNotificationCache = new Button("Clear Notification Cache");
btnClearNotificationCache.setOnAction(e -> {
notifiedAssignedToMeTickets.clear();
notifiedUnassignedTickets.clear();
});
row4.setAlignment(Pos.CENTER_LEFT);
row4.getChildren().addAll(showNotifications,cbShowNotifications,btnClearNotificationCache);
HBox row5 = new HBox(10);
//row1.setPadding();
Label autoReplyCompanies = new Label("Auto-Reply Companies");
autoReplyCompanies.setPrefWidth(DefaultValues.LABEL_WIDTH);
autoReplyCompanies.setPadding(new Insets(4,0,0,0));
txtAutoReplyCompanies = new TextField();
txtAutoReplyCompanies.setPrefSize(DefaultValues.TEXTAREA_WIDTH,20);
txtAutoReplyCompanies.setPromptText("(For Unassigned Tickets..)Seperate with ';' for multiple companies");
row5.getChildren().add(autoReplyCompanies);
row5.getChildren().add(txtAutoReplyCompanies);
//txtAutoReplyModules
HBox row5_2 = new HBox(10);
//row1.setPadding();
Label autoReplyModules = new Label("Auto-Reply Modules");
autoReplyModules.setPrefWidth(DefaultValues.LABEL_WIDTH);
autoReplyModules.setPadding(new Insets(4,0,0,0));
txtAutoReplyModules = new TextField();
txtAutoReplyModules.setPrefSize(DefaultValues.TEXTAREA_WIDTH,20);
txtAutoReplyModules.setPromptText("(For Unassigned Tickets..)Seperate with ';' for multiple modules");
row5_2.getChildren().add(autoReplyModules);
row5_2.getChildren().add(txtAutoReplyModules);
HBox row6 = new HBox(10);
//row1.setPadding();
Label autoReplyMessage = new Label("Auto-Reply Message");
autoReplyMessage.setPrefWidth(DefaultValues.LABEL_WIDTH);
autoReplyMessage.setPadding(new Insets(4,0,0,0));
txtAutoReplyMessage = new TextArea();
txtAutoReplyMessage.setPrefSize(DefaultValues.TEXTAREA_WIDTH,65);
row6.getChildren().add(autoReplyMessage);
row6.getChildren().add(txtAutoReplyMessage);
//cbStatistics
HBox row6_1 = new HBox(10);
Label searchStatistics = new Label("Process Statistics");
searchStatistics.setPrefWidth(DefaultValues.LABEL_WIDTH - 10);
searchStatistics.setPadding(new Insets(4,0,0,0));
cbStatistics = new CheckBox();
cbStatistics.setSelected(true);
cbStatistics.setPrefWidth(180);
row6_1.getChildren().addAll(searchStatistics,cbStatistics);
HBox row7 = new HBox(10);
//row1.setPadding();
Label searchUnassignedsLbl = new Label("Search Unassigned Tickets");
searchUnassignedsLbl.setPrefWidth(DefaultValues.LABEL_WIDTH - 10);
searchUnassignedsLbl.setPadding(new Insets(4,0,0,0));
cbSearchUnassigneds = new CheckBox();
cbSearchUnassigneds.setSelected(true);
cbSearchUnassigneds.setPrefWidth(180);
//row7.setAlignment(Pos.CENTER_LEFT);
row7.getChildren().addAll(searchUnassignedsLbl,cbSearchUnassigneds);
HBox row8 = new HBox(10);
//row1.setPadding();
Label searchAssignedToMe = new Label("Search Replied to u");
searchAssignedToMe.setPrefWidth(DefaultValues.LABEL_WIDTH);
searchAssignedToMe.setPadding(new Insets(4,0,0,0));
cbSearchAssignedToMeTickets = new CheckBox();
cbSearchAssignedToMeTickets.setSelected(true);
cbSearchAssignedToMeTickets.setPrefSize(DefaultValues.TEXTAREA_WIDTH,20);
row8.getChildren().add(searchAssignedToMe);
row8.getChildren().add(cbSearchAssignedToMeTickets);
HBox row9 = new HBox(10);
Label checkUpdateLbl = new Label("Check Updates");
checkUpdateLbl.setPrefWidth(DefaultValues.LABEL_WIDTH - 10);
checkUpdateLbl.setPadding(new Insets(4,0,0,0));
cbCheckUpdates = new CheckBox();
cbCheckUpdates.setSelected(checkUpdatesSetting);
cbCheckUpdates.setPrefWidth(180);
Button btnUpdateUpdater = new Button("Update Updater");
btnUpdateUpdater.setOnAction(event -> downloadUpdaterUpdate());
//btnUpdateUpdater.setPadding(new Insets(5));
row9.setAlignment(Pos.CENTER_LEFT);
row9.getChildren().addAll(checkUpdateLbl,cbCheckUpdates,btnUpdateUpdater);
HBox row10 = new HBox();
Label dummy = new Label("");
dummy.setPrefWidth(DefaultValues.LABEL_WIDTH);
Button btnSaveSettings = new Button("Save Settings");
btnSaveSettings.setOnAction(e -> {
if(txtEmail.getLength() == 0 || txtPassword.getLength() == 0 || txtRefreshTime.getLength() == 0)
showAlert(Alert.AlertType.ERROR,"","ilk 3 alan boş olamaz");
else{
Task<Void> task = new Task<Void>() {
#Override
protected Void call(){
shutDownCalled = true;
waitExecutorShutDown();
checkLicence();
Settings st = new Settings();
st.setEmail(txtEmail.getText().trim());
st.setPassword(txtPassword.getText().trim());
st.setRefreshTime(Integer.parseInt(txtRefreshTime.getText().trim()));
st.setUserCountForPointCalculation(txtUserCountForPointCalc.getLength() == 0 ? DefaultValues.userCountForPointCalculation : Integer.parseInt(txtUserCountForPointCalc.getText()));
st.setShowNotifications(cbShowNotifications.isSelected());
st.setAutoReplyCompanies(txtAutoReplyCompanies.getText().trim());
st.setAutoReplyModules(txtAutoReplyModules.getText().trim());
st.setAutoReplyMessage(txtAutoReplyMessage.getText().trim());
st.setSearchUnassignedTickets(cbSearchUnassigneds.isSelected());
st.setSearchAssignedToMeTickets(cbSearchAssignedToMeTickets.isSelected());
st.setCheckUpdates(cbCheckUpdates.isSelected());
st.setProcessStatistics(cbStatistics.isSelected());
Settings.saveNormalBotSettingsToFile(st);
settings = st;
needLogin = true;
initData(false);
return null;
}
};
new Thread(task).start();
mainTabs.getSelectionModel().select(0);
}
});
row10.getChildren().addAll(dummy,btnSaveSettings);
VBox vb = new VBox(9);
vb.setPadding(new Insets(10,10,0,10));
vb.getChildren().addAll(row1,row2,row3,row3_1,row5,row5_2,row6,row6_1,row4,row7,row8,row9,row10);
return vb;
An HBox makes no guarantee about the amount of space it actually assigns to any child node that is contained inside it. It merely guarantees to place them in order, with a minimum gap if you specify a spacing, and makes a best effort to size each child node to its preferred size. Many factors which are beyond your control will affect the actual size of each node, including font sizes (which depend on the available fonts), total size available to the HBox, etc etc. All these may change depending on the platform the application is running on, including depending on the JDK version.
So trying to line things up vertically by placing them in a collection of HBoxs and setting the preferred sizes of the child nodes is simply not a reliable way to approach this (and is not designed as such). The problem is there is no real way to connect the layout of one HBox to the layout of another HBox: they are all laid out independently. If you want to lay components out so they are aligned relative to each other both horizontally and vertically, you should use a GridPane, which is specifically designed for that purpose.
It is generally a very bad idea (not just in JavaFX; this applies to most UI toolkits) to hard-code sizes of anything, so anytime you are using this as a solution, there is almost certainly a better approach.
The basic idea behind using a GridPane would look like:
GridPane grid = new GridPane();
// padding around entire grid:
grid.setPadding(new Insets(4);
grid.setHgap(10);
grid.setVgap(9);
Label nameLbl = new Label("Login Email");
// column 0, row 0:
grid.add(nameLbl, 0, 0);
txtEmail = new TextField();
txtEmail.focusedProperty().addListener((observable, oldValue, newValue) -> {
if(!newValue)
checkLicence();
});
// column 1, row 0, span 2 columns:
grid.add(txtEmail, 1, 0, 2, 1);
// ...
Label searchAssignedToMe = new Label("Search Replied to u");
// column 0, row 7:
grid.add(searchAssignedToMe, 0, 7);
cbSearchAssignedToMeTickets = new CheckBox();
cbSearchAssignedToMeTickets.setSelected(true);
// column 1, row 7, span two columns:
grid.add(cbSearchAssignedToMeTickets, 1, 7, 2, 1);
Label checkUpdateLbl = new Label("Check Updates");
// column 0, row 8:
grid.add(checkUpdateLbl, 0, 8);
cbCheckUpdates = new CheckBox();
cbCheckUpdates.setSelected(checkUpdatesSetting);
// column 1, row 8:
grid.add(cbCheckUpdates, 1, 8);
Button btnUpdateUpdater = new Button("Update Updater");
btnUpdateUpdater.setOnAction(event -> downloadUpdaterUpdate());
// column 2, row 8:
grid.add(btnUpdateUpdater, 2, 8);
// ...
Button btnSaveSettings = new Button("Save Settings");
btnSaveSettings.setOnAction(...);
// center button horizontally in its cells (it spans the whole row):
GridPane.setHalignment(btnSaveSettings, HPos.CENTER);
// column 0, row 9, span 3 columns:
grid.add(btnSaveSettings, 0, 9, 3, 1);
You can completely configure how any potential extra space is allocated among the columns (using ColumnConstraints instances), among the rows (using RowConstraints instances), and how the controls are aligned within their individual cell(s). You can also specify these on a node-by-node basis if you need.
You probably want, for example, hgrow of the three columns to be SOMETIMES, SOMETIMES, and ALWAYS; you may need to set the fillWidth of the TextInputControls to true.
See the GridPane documentation, which explains this all completely.

How to span 2 column of gridLayout?

I want to span right 2 column of 3 column in grid layout, but I do not know how to do, someone can give me some guidance on how to do ?
Example code and image is below:
#PostConstruct
public void PostConstruct(Composite parent) {
toolkit = new FormToolkit(Display.getDefault());
form = new ScrolledForm(parent, SWT.V_SCROLL);
form.setBounds(0, 0, 650, 478);
form.setExpandHorizontal(true);
form.setExpandVertical(true);
form.setBackground(toolkit.getColors().getBackground());
form.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
form.setFont(JFaceResources.getHeaderFont());
form.setText("DOCUMENTATIONS");
toolkit.decorateFormHeading(form.getForm());
GridLayout cl = new GridLayout(3, true);
form.getBody().setLayout(cl);
sectionSelection = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
sectionSelection.setText("");
sectionClientSelection = toolkit.createComposite(sectionSelection);
sectionClientSelection.setLayout(new GridLayout());
sectionClientSelection.setLayoutData(new GridData(100, 100));
sectionSelection.setClient(sectionClientSelection);
createSelectionSection();
sectionDefinition = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
sectionDefinition.setText("");
sectionClientDefinition = toolkit.createComposite(sectionDefinition);
sectionClientDefinition.setLayout(new GridLayout());
GridData gridData = new GridData(SWT.FILL,GridData.VERTICAL_ALIGN_END);
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = GridData.FILL;
sectionClientDefinition.setLayoutData(gridData);
sectionDefinition.setClient(sectionClientDefinition);
createDefinitionSection();
}
You need to set the layout data for the Section rather than the Composite in the section.
sectionDefinition.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

GUI in design page and GUI when RUN is not the same (Eclipse)

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.

How to set width for GridData?

I was building an UI by using GridLayout/GridData. The layout supposes to have 3 section, one is the headingComposite, one is the leftEditorComposite, one is the rightEditorComposite. But my problem here is, I dont want my leftEditorComposite/rightEditorComposite's width layout be changed by the content. (like the name textbox, if the input get longer, then the leftEdtiorComposite's width will become longer too.) Is there a way to make them as a fix size width? thanks a lot!
GridLayout layout = new GridLayout(2, false);
mainComposite.setLayout(layout);
scrolledComposite.setContent(mainComposite);
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
data.horizontalSpan = 2;
headingComposite = new Composite(mainComposite, SWT.BORDER);
headingComposite.setBackground(getBackground());
headingComposite.setLayoutData(data);
data = new GridData(GridData.FILL_BOTH);
leftEditorComposite = new Composite(mainComposite, SWT.BORDER);
leftEditorComposite.setBackground(getBackground());
leftEditorComposite.setLayoutData(data);
data = new GridData(GridData.FILL_BOTH);
rightEditorComposite = new Composite(mainComposite, SWT.BORDER);
rightEditorComposite.setBackground(getBackground());
rightEditorComposite.setLayoutData(data);
If you know the size of each composite, you could provide a widthHint for both your Composite objects.
leftEditorComposite.widthHint = 200;
and
rightEditorComposite.widthHint = 200;
Alternatively, you can read this question, and hopefully you will get your answer:
How to align two composites in a parent composite without using widthHint and heightHint

SWT: Width of expandbar

at the moment I'm playing a little bit around with SWT and try to implement an expandbar:
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
ExpandBar bar = new ExpandBar(container, SWT.V_SCROLL);
Composite newConstraint = new Composite(bar, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
newConstraint.setLayout(gridLayout);
Label sourcelbl = new Label(newConstraint, SWT.NONE);
sourcelbl.setImage(getMyImage("source.png"));
sourcelbl.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER,
true, false));
Label spacelbl = new Label(newConstraint, SWT.NONE);
Label targetlbl = new Label(newConstraint, SWT.NONE);
targetlbl.setImage(getMyImage("target.png"));
targetlbl.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER,
true, false));
ListViewer lvSource = new ListViewer(newConstraint);
lvSource.setContentProvider(new ConstraintDialogContentProvider());
lvSource.setLabelProvider(new ConstraintDialogLabelProvider());
lvSource.setInput(fm);
Combo constrainType = new Combo(newConstraint, SWT.NONE);
constrainType.setItems(new String[] { "require", "exclude" });
constrainType.setLayoutData(new GridData(GridData.CENTER,
GridData.CENTER, true, false));
ListViewer lvTarget = new ListViewer(newConstraint);
lvTarget.setContentProvider(new ConstraintDialogContentProvider());
lvTarget.setLabelProvider(new ConstraintDialogLabelProvider());
lvTarget.setInput(fm);
ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0);
item0.setText("New Constraint");
item0.setHeight(newConstraint.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
item0.setControl(newConstraint);
omposite existingConstraints = new Composite(bar, SWT.NONE);
gridLayout = new GridLayout();
gridLayout.numColumns = 2;
existingConstraints.setLayout(gridLayout);
........
ExpandItem item1 = new ExpandItem(bar, SWT.NONE, 1);
item1.setText("Existing Constraints");
item1.setHeight(existingConstraints.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
item1.setControl(existingConstraints);
item0.setExpanded(true);
bar.setSpacing(8);
return container;
}
The problen then is the width, which doesn't seems to be computed:
Without the extendbar, everything works fine and the width is automatically computed:
How can I let the extendbar compute the width???
Cheers,
Phil
The ExpandBar size computation only appears to take the size of the ExpandItem text in to account and ignores the size of the control in the item.
You would have to override the ExpandBar.computeSize method to change this (and also ExpandBar.checkSubclass to stop that rejecting your subclass).
Or you could just include spaces at the end of the text for the ExpandItems to fudge the calculated size.
Based on greg-449's answer, I found another workaround, which is to set a widthHint for the ExpandBar:
ExpandBar expandBar = new ExpandBar(this, SWT.BORDER);
GridData gridDataExpandBar = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
gridDataExpandBar.widthHint = 150;

Categories