I have a fairly large (6000 lines) java application with over 40 buttons etc. and fixed window size.
This is creating problem for people who wants to use it for some it is too small for others it is too large with no scrolling! How can I retroactively make it fit different screens?
Thanks
If yours is a Swing GUI (you have not mentioned this yet)
Don't use fixed size anything.
Use layout managers and nested JPanels to do the heavy work for you.
One comment to your question mentions using GridBagLayout, but I suggest that you avoid using this, that you instead use nested JPanels that use simpler layout managers, or use MigLayout.
To fill the Screen, set the extended state appropriately: setExtendedState(JFrame.MAXIMIZE_BOTH)
Related
When using window builder pro is it necessary to use a container for each time you wish to add a list etc? e.g. do you need to add a container to put the list into?
I'm not sure about pro version or not or if I'm understanding your question correctly or not. But if your talking about lists in windowsbuilder, you don't need to place them in a particular container besides of course the main frame your working on. You need at the very least a frame though.
EDIT: But if you want your gui to be flexible/resizable you might wanna think about using layouts to make it resize in a reasonable way. If your making a fixed size program then it doesn't matter much I guess.
I've heard that putting the same-level component on top of another same-level component is bad practice.
I'm talking about JPanels in this case. I currently divide everything into separate JPanels where each has its own layout, and then I add them to the main content pane (JPanel). I feel like this way is much easier than having to configure a layout that will work for all my components that can be all over the place. Is my logic flawed?
There is nothing wrong with having panels inside of panels. However, if you are doing a lot of that, you may want to consider a layout manager (my favorite is MiGLayout) that supports fairly complex arrangement of controls without using tons of nested panels.
At the end of the day, use a composition that makes it easier for you to maintain your code. If you have groupings of controls that are independent of each other, then having them in separate panels is good design - it allows you to split that panel out (for testing, or even for creative windowing in the UI). If the sets of controls are intrinsically tied to each other, consider a single panel with an advanced layout manager.
In some cases, you'll have a small amount of binding between two panels (classic example is one panel with a list and another panel with a detail view for the selected item in the list). In this case, I generally use two separate panels, and two separate presentation models, then bind the current selected item in one model to the parent of the inspector panel. But if you find that you are using values from multiple panels for things like validation, data storage, etc... then you may have things split into too many panels.
I've done a lot of this over the years, and the position I've settled on is to compose my UIs along logical lines of the underlying presentation models that back the views. Very rarely do I let the layout of the UI drive how many panels I use, etc... - MigLayout (and I'm sure there are others) make even complex UI layouts fairly straightforward, and it's much better to design the classes for the view and model in a way that make the code easier to test and maintain.
Let's imagine situation where you're making the layout for a webpage. In HTML you can put the stuff in divs and use CSS to set positioning, e.g. size, positioning, etc.
Let's have another situatinon, but same requirements. You're programing in Java Swing, and you also want to make layout with similar requirements, e.g. size, positioning, etc.
I haven't found layout managers useful in this situation, because they make it one way, but never as you want it, e.g. one part will be next to another part, and it will have some size.
In short: I want the layout to handle positioning and setting sizes of GUI parts as happens with divs in HTML & CSS. I'm programing it in Java Swing.
I've tried swinghtmltemplate, but know about xito try to look through these projects, maybe you will find good solution for you. And yes, there is MiG layout
Is it possible to overlay multiple JSliders so I can see the "thumbs" on both (I've tried disabling the painting of the track and setting opacity to false but one still hides the other)? Basically I'd like to create a component that allows the user to define a range (and I didn't really want to write a custom one since it has most of the attributes of a slider). If there is another way I could do that with a slider, that would work too.
thanks,
Jeff
Ah, I found it (i must not have been seraching on the right terms). Swing labs as a JXMultiThumbSlider that I think will do the trick.
http://swinglabs.org/hudson/job/SwingX%20Weekly%20Build/javadoc/org/jdesktop/swingx/JXMultiThumbSlider.html
I recently had the same problem, I wanted a slider with two thumbs. I didn't get into it too much, and what I ended up doing to get the range is simply putting two sliders and in the "onSliderChange" event listener prevented one beeing smaller than the other and the other bigger than the one. I don't beleive Swing has a two-thumb-Slider, although it might be a cool new feature to add, so I think this is your best bet.
JIDE has a RangeSlider with 2 thumbs (and a nice extra one on top to move both thumbs at once (e.g. drag the range around) in their open source common layer: http://www.jidesoft.com/products/oss.htm
In the Java Swing app I made it seems to me that all the component are too tightly packed.
In QT one can specify padding and margins for the layout.
Is there something similar for swing?
alt text http://img12.yfrog.com/img12/9612/screenshotscreenerconfi.png
Here is a screen shot of my application that I thing is too tight (is it? what do you think?.
Thanks.
Take a look to the GridBagLayoutManager. Its the most compex layout manager but everything can be acomplished whith it.
It uses the GridBagConstraintObject which has the inset property, it specifies the separation to the top, bottom, left and right components.
example: GridBagConstraintObject.insets.left=20
You could use MiGLayout as your layout manager. It allows all kinds of customizations, including margins/paddings.
You could achieve a much better layout for the example above by using DesignGridLayout in just a couple of lines of code (one per row in your layout). DesignGridLayout will automatically use the correct spacing for the runtime platform.
besides I would highly suggest that you DON'T use TitledBorders in your form because it prevents ANY LayoutManager (as advanced as it may be) from automatically aligning correctly the various components across different groups. Instead you could use a JLabel with a JSeparator (there are examples in DesignGridLayout, but this works with any other LayoutManager).
Since Java 1.6 swing there is a new GroupLayout manager that make this kind of works easier.
For instance there is a method: setAutoCreateGaps() that:
...you add two components to a SequentialGroup a gap between the two components is automatically be created...
For instance:
What LayoutManager are you using? Adding margins is quite easy, it depends however on the specific LayoutManager used.
FormLayout is another good layout manager. With a good GUI editor like JFormDesigner it makes GUI building easy enough. JFormDesigner actually automatically adds sufficient padding in most cases. I have to recommend against using GridBagLayout. It does the job alright, but is very complex which makes it difficult to use and maintain.