How to set custom width for part sash container? - java

I'm new to Eclipse E4. I'm using part sash container. Is there a way to reduce the width of the left side? By default it container is separated by 50:50. I need that to be 30:70.
Sample screenshot. Here I need to reduce the width of left side. so that right side will have more space:

You do this by putting the relative sizes of the container's children in the Container Data field of each child.
So if you have two children for your part sash container the first child could have a Container Data value of '30' and the second child a value of '70'.
Note: It is better to use larger relative size values to get smoother resizing - so something like 3000 and 7000 in this case. It is just the relative values that matter as far as the sizing is concerned.

Related

JavaFX scale components to fit parent without binding?

I am writing a JavaFX application which will have user definable number of components and I am looking for easy way to scale all groups so that no matter of the number everything will fit:
For example I have a Pane, than in the pane I might have > 0 number of groups of components. Each group consists of several TilePanes and each of those TilePanes can accommodate other components.
I would like to be able to create any number of groups (same structure) as described so that when the number of groups increases the components in the group will decrease size to fit in the Pane. The difficulty is that while the program runs it will be adding components in the TilePanes of each group and those components need to be resized properly to fit.
Currently I have the sizes hard coded, but as explained I need to create configurable number of groups (set on initializations).
Is there an easy way to get this done without having to bind all the elements to the size of their parent ? I thought TilePane will restrict the size of the elements inside, but as it turned out, even when I set the max size for the TilePanes, large components don't get resized.
Thanks

How to make a JScrollPane that encompasses a collection of points?

I realize that there's another question relating to "infinite" JScrollPanes, however I think that what I'm looking for is something that is subtly different.
Basically, I have a collection of objects which can be dragged in any direction, and the extent of the scrolling viewport should always encompass the bounding rect of all those objects. To put it another way, the document has no fixed "origin". Thus, if you drag an object to the left, off the edge of the screen, then the viewport extent should expand in the negative direction to encompass that object's new position. (It should also auto-scroll as you drag, but that's a separate problem I realize.)
I'm not sure how to do this using the JScrollPane API, which seems to want you to set the preferred size of the underlying component, but doesn't seem to have the concept of an offset or origin for that component. (The underlying JViewport seems like it would be able to do it, but I can't really figure out the JViewport API.)
The scroll pane and view port actually have nothing to do with it. What you need to is change the preferred size of the view ports view and let the scroll pane/view port take care of this rest.
Basically, what you need to do, is calculate the widest and highest points on your component and invalidate the view port, to force to recalculate it's layout requirements.
Create yourself a custom component (using a JPanel for example) and override the getPreferredSize method. This method should return the required size of your component.
When the size requirements change, call revalidate()
OK so it turns out that the simple answer is that scroll panes cannot scroll to negative coordinates. What you have to do, as #MadProgrammer suggested, is maintain a separate offset coordinate which is a Point. The offset stores the top/left coordinates of the entire document. When rendering individual objects, set the transform of the Graphics2D object such that they are shifted down and to the right by the offset amount, so that all object are drawn at coordinates that are positive numbers even though in reality they may be located at negative coordinates. Similarly, when calculating the preferredSize for the scroll pane, add in the offset to the document width and height. Coordinates from scroll bar events also need to be offset as appropriate.
This allows you to maintain the illusion that the document bounds are not constrained to be positive numbers, and the document's boundary can expand infinitely in any direction.

How to "anchor" SWT widgets?

I'm trying to make a simple browser with the SWT library. I'm having a problem though trying to get objects to anchor to the top left and such.
I'm using Eclipse and using the layout assistant I set the anchors to top-left and all the other options.
Basically I want the browser control to auto size. Thank you! :D
The layout type I am using is the Form Layout (It was suggested on the SWT help page for using anchors.)
For what you're trying to do (attach the widget to the sides of its parent), it's enough to use the single-argument constructor of FormAttachment. This works:
fd_browser.top = new FormAttachment(0);
fd_browser.left = new FormAttachment(0);
fd_browser.bottom = new FormAttachment(100);
fd_browser.right = new FormAttachment(100);
What that says is "attach the top edge to the 0% vertical postion of the container," "attach the left edge to the 0% horizontal position," "attach the bottom edge to the 100% vertical position of the container," and "attach the right edge to the 100% position of the container." In other words, the top and left edges will be at the container origin + 0 and the bottom and right edges will be at the container origin + 100% of the container size. It sounds complex in words but I think it's actually very intuitive.
Using the two-argument c'tor as your code does, is specifying hard-coded offsets from the container's 0,0 position (450 down and 845 across), which is essentially telling the Browser widget to be fixed size. Offsets in FormLayout are really only useful for setting margins or, um, offsets from edges of the container or other widgets. :-)
I'd suggest read the JavaDocs for FormAttachment and FormLayout again - once you "get" it I think it will be easy for you to use. There are also probably some examples on the SWT Snippets page.

Java Swing Gridlayout: Accessing Specific Coordinate

I'm creating a Java swing GUI and I have formatted a JPanel to use a GridLayout. I need to access a specific "box" (i.e. specific coordinate) of the grid, but I cannot see a way to do so.
How can I do this?
You shouldn't depend on GUI code (the View) to give you information about program data (the model). The best solution would be to "know" which component is where from the start--maybe you should have a data structure (2D array?) that holds the components and is updated whenever something's added to the grid.
If you want a quick and very-dirty fix, though, you could start playing games with JPanel.getComponentAt(). This requires pixel coordinates, though, so you'd need to do some reverse-engineering to figure out how much space a given grid square takes up. The space between grid squares is given by your GridLayout object. This is not recommended whatsoever though. I'm just including it in the interest of completeness (and since it's a more literal response to your question).
In GridLayout, "The container is divided into equal-sized rectangles." You can add an empty, transparent component in places you want to appear empty, e.g. new JLabel(""). See also GridBagLayout and Using Layout Managers.

SWT ScrolledComposite cutting off information.

I'm making an application that has many lines of data coming back from a Database stub(which will become an Oracle database), and for some reason the scroll bar stops at about the 500th element. I'm wondering if there's anyway to have all the elements show within the scroll bar.
I'm assuming here that you're using Windows, because there is a fairly general problem with scrollbars on Windows: the maximum value is a short int, 32,768. Therefore, if the height of the inner composite of a ScrolledComposite is greater than 32,768 pixels, the composite will be clipped.
I haven't found a robust way of fixing this, but there is a workaround: separate the scrollbar from the composite that you wish to scroll. You can't create a ScrollBar, but you can make a ScrolledComposite that is precisely as wide as a ScrollBar, then attach a ScrollListener to it and have it adjust the layout position of the scrolling composite.
Somewhere I have a snippet, but I'm not even exactly sure if this diagnosis applies to your scenario.
You might need to set the minimum and maximum values of the ScrollBar. You would use the setMinimum() and setMaximum() methods, respectively.
It's also a good idea to set the page increment. This is the number of scroll lines that the selected value changes by when the user clicks the area between the thumb and the arrow buttons, or presses the Page Up or Page Down buttons. You would use the setPageIncrement() method.
Finally, Oracle may impose a maximum number of rows you can retrieve from a table. I believe the default is 500 rows.

Categories

Resources