I´ve got some questions which shouldn´t be hard for a plugin developer.
My Plugin should read an INI File and then put the strings into a list. So how do I read a INI File in PDE is there any class? A example code would be amazing.
Further on I´m using Grid Layout, but I don´t know how I can control the columns. I have to set it at the beginning with:
layout.numColumns = 3;
But how do I change the row for a added control? (Button first row, text second row, list third row)
How can I add when I´m using GridLayout a vertical Scrollbar for my Listbox. It does not work for me in a GridLayout with the following code:
List listbox = new List(newproject, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
Rectangle clientArea = getShell().getClientArea ();
SAFETYVersions.setBounds (clientArea.x, clientArea.y, 100, 100);
I think when I´m using GridLayout i also have to define the size of the listbox?
-Last thing is there a simple checkbox in the widget library from SWT?
About listbox size, try following:
GridData gd = new GridData();
gd.heightHint = 100;
gd.widthHint = 100;
listbox.setLayoutData(gd);
listbox should be in GridLayout, of course.
My Plugin should read an INI File and then put the strings into a list. So how do I read a INI File in PDE is there any class? A example code would be amazing.
Take a look at the IFile interface.
Further on I´m using Grid Layout, but I don´t know how I can control the columns.
You use SWT.PUSH to put the widgets onto the Grid Layout. If layout.numColumns = 3;, that's 3 pushes for each row.
If you want a more complicated layout than a simple grid, you have to use Composites to group the widgets.
Last thing is there a simple checkbox in the widget library from SWT?
Yes, it's a Button with a SWT.CHECK style.
I would recommend you to use a property file instead.
Check out the java.util.Properties for more details.
You have everything there to help you out.
Drop me a line if you have problems and i will write a quick blog post for this at my blog.
Geirr
Related
I'm trying to develop an application to sort photos, based on the tinder principle.
The picture below is a screenshot of my current GUI, I want to combine the 2 middle columns on the first row so that the label for the photo to be placed in is nicely in the center.
This GUI has been developed in intellij using the gridlayoutmanager. Could someone happen to help me solve this problem?
Kind regards
Current GUI:
This GUI has been developed in intellij
Don't use the IDE to generate your GUI code. Write the code yourself so you are in full control
using the gridlayoutmanager
You are never forced to use a single layout manager. You can create multiple panels each using a different layout manager to achieve your desired layout.
I want to combine the 2 middle columns on the first row
Create a panel. Add the "Dislike" and "Like" buttons to the panel. Add the panel to the parent panel.
I am making a simple GUI and I want to put them in a GridLayout like this
areaLabel, sAreaLabel, volumeLabel
areaField, sAreaField, volumeField
blank, radiusLabel, blank
blank, radiusField, blank
so the layout would be made like this
'''
new GridLayout(4, 3);
'''
I know how to use the The problem is that I don't know how to put components into specific places. I looked through the Java API and just online but I couldn't find anything. Do I just need to add blank components in the places I've indicated or is there a more elegant solution?
The order of the components is defined by the rows, columns, grid orientation and the order you add the components. See https://docs.oracle.com/javase/8/docs/api/java/awt/GridLayout.html
You could add blank JLabels as placeholders for the blank cells. Something like
JLabel blank = new JLabel("");
myGrid.add(blank);
I have a TableViewer which I know will always have one row of data in it.
When I have data for that table, I can call setInputData(...) and pass the one object with Arrays.asList(...) to have the Table sized correctly displaying the one row of data.
When I do not have the object, I still want the Table to be sized to display only one row. However, if I use this: setInputData(new ArrayList<Object>(0)), the Table is auto-sized to show around 3 & a half blank rows. How can I get the Table to always be sized to display only one row?
I should mention that I'm using GridLayout for the Composite that the TableViewer is within as well as for the TableViewer.
I have tried setting the bounds for the SWT Table within the TableViewer to be the size of a single item, but that hasn't helped. I haven't found any similar questions on SO or through a general Google search, however in this question: TableViewer shrinks to a single row with a scroll bar when new input is set, the asker was able to have his Table sized to show one row. Unfortunately, I don't have enough rep. to comment asking him how he did that.
EDIT: Adding some more relevant code
final ScrolledComposite scrolledComposite = new ScrolledComposite(parentComposite, SWT.V_SCROLL);
scrolledComposite.setLayout(new GridLayout());
scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
scrolledComposite.setAlwaysShowScrollBars(true);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
TableViewer tableViewer = new TableViewer(scrolledComposite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
// I'm setting the LabelProvider, ContentProvider here.
GridData gridData = new GridData();
gridData.heightHint = tableViewer.getTable().getItemHeight();
tableViewer.getTable().setLayoutData(gridData);
scrolledComposite.setContent(tableViewer.getControl());
scrolledComposite.setMinSize(tableViewer.getTable().getGridLineWidth(), tableViewer.getTable().getItemHeight());
And then, in a separate method:
tableViewer.setInputData(objectList); // This may be empty or have exactly one object
You can query the table to compute its size for one row like this
Point Site = table.computeSize( SWT.DEFAULT, table.getItemHeight() * 1 );
Next you need to tell the layout to reserve that much space for the table. In a GridLayout, for example, use gridData.heightHint
To anyone arriving at this link looking for a solution, building off of Rüdiger Herrmann's answer, what finally worked for me was to create the TableViewer inside a Composite which is then placed inside the ScrolledComposite. (This was found through another StackOverflow link which stated that a Control needs to be placed inside a Composite within the ScrolledComposite for it to show up correctly.) Then the Composite needs to be set to the ScrolledComposite like: ScrolledComposite.setContent(Composite).
After setting both, the ScrolledComposite & the Composite Layouts to FillLayout & setting the size of the ScrolledComposite to be tableViewer.getTable().computeSize(SWT.DEFAULT, tableViewer.getTable().getItemHeight()), I was able to get the correct height for the TableViewer.
Once that's done, after tableViewer.setInput(objectList); is called, I set the size to the TableViewer with: tableViewer.getTable().setSize(tableViewer.getTable().computeSize(tableViewer.getTable().getClientArea().width, tableViewer.getTable().getItemHeight()));
I'm new to gwt and I want a page like this...
***********Header panel*************
Tab1 *** Root panel 1
Tab2 ***
I managed to create everything but I don't know how to make my tabs vertical like that...
My code is,
public void onModuleLoad() {
headerRightPanel.add(portalLabel);
//Tabs which I want it vertical
headerRightPanel.add(orderMenu);
headerRightPanel.add(homeMenu);
headerRightPanel.add(logout);
logout.addClickListener(this);
homeMenu.addClickListener(this);
orderMenu.addClickListener(this);
headerPanel.setVisible(false);
homeMenu.setStyleName("menuEnabled");
orderMenu.setStyleName("menuEnabled");
logout.setStyleName("menuEnabled");
headerRightPanel.setStyleName("menuPanel");
portalLabel.addStyleName("portalLabel");
Image img = new Image("images/logo1.PNG");
headerLeftPanel.add(img);
headerLeftPanel.setStyleName("menuLeftPanel");
headerPanel.add(headerLeftPanel);
headerPanel.add(headerRightPanel);
RootPanel.get("imageContainer").add(img1);
RootPanel.get("sendButtonContainer").add(login);
RootPanel.get("headerContainer").add(headerPanel);
}
If you want to keep elements in a vertical position, use VerticalPanel:
http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/VerticalPanel.html
GWT has many components, unfortunatelly those ones are using tables, not css.
But in this example I would propably go with a css solution. And stay with divs only (FlowPanel with css class). GWT Vertical and Hirozontal Panels are using tables underneeth, that is a ... rough solution for creating layout.
I would mostly adise using UIBinder:
http://www.gwtproject.org/doc/latest/DevGuideUiBinder.html
If that is not too hard for you. But it would help you create a HTML fil next to java, and is more flexible when building complex structures.
Example: FlowPanel will produce a DIV in DOM, so you can add classes to it, set styles, css, hide it, show it, etc.
FlowPanel flowpanel = new FlowPanel();
flowpanel.addStyleName("css-name"); // yuo can add many css classes
flowpanel.hide().show()// you can hide and show it.
flowPanel.add(new FlowPanel())// you can add other elements to it.
Your whole structure is wrong. Rootpanel is the parent layout to which you add other things such as panels and widgets. Are you looking for something like disclosure panel?
Here is the demo of all the panels and widgets in gwt
http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwDisclosurePanel
Please see the image attached. I'm a beginner at Java GUI and was hoping someone could guide me in choosing a Layout Manager for GUI like this. I know I might have to use nested layoutmanagers, but I'm not sure which would help me accomplish this job.
Here's an idea:
Use a BorderLayout in the main JPanel. Set the JList at the CENTER part
On the EAST part of the above layout, add a new JPanel with a GridLayout of 6 rows, 2 columns
On the GridLayout, add each of the labels, buttons, text fields, etc. in the same order as they're defined - from top to bottom and from left to right.
Alternatively: you could use a 7x2 GridLayout and fill the two positions above the buttons with empty text fields, to separate the labels/fields above from the buttons below.
check out DesignGridLayout, it will be perfectly suited for this form I think
just look at their example:
with just a few lines of clean code:
layout.row().grid(label("Last Name")) .add(lastNameField) .grid(label("First Name")) .add(firstNameField);
layout.row().grid(label("Phone")) .add(phoneField) .grid(label("Email")) .add(emailField);
layout.row().grid(label("Address 1")) .add(address1Field);
layout.row().grid(label("Address 2")) .add(address2Field);
layout.row().grid(label("City"), 1) .add(cityField);
layout.row().grid(label("State")) .add(stateField) .grid(label("Postal Code")) .add(postalField);
layout.row().grid(label("Country"), 1) .add(countryField);
layout.emptyRow();
layout.row().center().add(newButton).add(deleteButton).add(editButton).add(saveButton).add(cancelButton);