Null layout screwing my program in netbeans - java

I've designed my program in both null layout and the free design layout, however, when I compiler my program and run it with the null layout the window gets resized (Despite my original size, and specifying the default size, minimum, maximum etc) and the buttons are not visible anymore. However, when I compile and run my program in free design layout, the size is perfect and it works great, but my components get screwed up when I perform all sorts of operations (example : making a component visible, setting the text, etc). Is there any fix to this? I believe this is a netbeans bug but I can't tell. Please help this is a disaster. I'm using Netbeans 7.0.1

Is there any fix to this?
Yes, use a layout manager. Using a null layout is almost never the way to go.

If you need to rearrange the components or change labels at runtime, the 'free design' is probably not the way to go. Its not designed for this, and it really has nothing to do with netbeans. You will need to understand how to use the appropriate layout managers to make it do what you want.
In addition to the standard layout managers, you might also want to look at Mig Layout.
IIRC, netbeans also offers an XY layout for absolute positioning. This is only a bit better than null layout though, because your UI will look bad once it hits another system, but if you don't care about that then that might be the right answer for you.

Related

Graphical Layout Editor not DROPPING

The layout editor itself is working fine, but it doesn't want DROP where I want it to drop.
It's only dropped in the very top left corner, and gravity doesn't change anything. If I drag it elsewhere, it just doesn't work.
It's the same anywhere, whether it's a different xml or just a new xml.
Is this an eclipse problem or a Java problem?
Thanks, and Happy New Year!
Do you come from an XCode or Visual Studio background? If so, yes, the "graphical layout editor" for Android is weird, as it depends chiefly on relative positioning of elements, unless you user AbsoluteLayout controls, which give you pixel-by-pixel positioning power.
This looks to be a good overview of the different kinds of layouts available in Android... the thing you have to remember about Eclipse and its ilk is that they assume you want to use certain layouts (Linear appears to be the default), to make it easier for you to create layouts that scale appropriately to size, irregardless of pixel density or resolution.
http://www.sitepoint.com/know-your-layouts-in-android/
Good luck!

Cross platform UI spacing/padding

I have written a Java UI using the SWT UI library and the MigLayout layout library.
This page shows screenshots of the UI on Windows, Linux and OSX: http://mchr3k.github.com/org.intrace/screenshots.html
On Linux and OSX my UI has a lot more padding and spacing which I feel wastes a lot of screen space. Is this normal for these platforms? If not, what is the best way to work around this?
EDIT: the linked screenshots have now been updated and no longer show an extra gap on OSX as I have explicitly set the margins on some of my UI elements to 0. The OSX UI is still quite spaced out but I assume that this is correct for the platform.
This is Mikael Grev, the creator of MigLayout.
As someone else mentioned this is a feature of MigLayout. Instead of using x number of pixels (you can of course use that too) by default it is using gaps like related, unrelated and paragraph. These correspond to different sizes in different UI toolkits. For instance on OS X the recommended white space between components is larger than on Windows.
So, yes, this is how it's supposed to look and it will look correct for a native OS X user.
You do seem to have too much white space at the bottom of the Output pane though, in both OS X and Windows.
You can use the PlatformDefaults class in MigLayout to either force a platform or to change the default gaps. Check the source code if you want to know what's happening behind the scenes.
And remember, this is a feature so that every developer won't have to keep track of how to spacing should look like on different platforms, which is kind of hard.
Cheers,
Mikael
That's actually a feature of MigLayout, if I recall correctly. If you don't want this I am sure you could so configure MigLayout. Otherwise, you could use a different layout manager (but I still highly recommend a table-based one) which uses constant spacing for all platforms (such as my MatrixLayout).

Converting an AWT application to SWT/JFace

I am currently toying with the idea of converting a small/medium sized project from AWT to SWT, although Swing is not totally out of the picture yet.
I was thinking about converting the main window to an SWT_AWT bridge object, but I have no idea how the semantics for this work. After that, I plan to update dialog for dialog, but not necessarily within one release. Is this possible?
Has someone done a conversion like this and can give me some hints? Is there maybe even a tutorial somewhere out there? Is there maybe even a tool that can automate parts of this? I have tried googling, but to no avail.
Update: One additional thing is: Currently, this is a netbeans project. Might be of help or not, I don't know.
We have done this quite a few times. But only because we are going from a Swing application to an Eclipse RCP application not because we like messing with things. This project will really let you know whether you've separated your controller/model code from your view code.
One suggestion is to not try and convert everything all at once. You will end up with a bunch of mixed code that doesn't work at all. You can start at converting portals. I would consider a portal anything within a Tab, Dialog, or Window, essentially self contained unit. If you have a window that opens up, create the Window in SWT, but make it's contents the existing AWT/Swing. This should be fairly straight forward and allow you to get used to the (I really hope they weren't drunk and had a good reason for this) way of instantiating and associating parent/child controls.
One gotcha that can occur is with transparent components. Swing, with the exception of a "window" class is all rendered in Java. This makes it very easy to render things the way you want them. In SWT, there are some restrictions:
Borders. If you use SWT.BORDER you are stuck with whatever color the native component uses. Your best bet is to use a PaintListener and render your own borders if you want them in a different style or color.
Transparent labels, progress bars. I have not been able to get Labels or Progress Bars to have a transparent background. If you want them to take on the parent color, or drawing you will need to render the text and other controls yourself.
Controls. There are composites and controls in SWT. Think of Controls as the basic native controls that do all the native API calls. These cannot be subclassed, which makes things difficult.
Tables will give you the most trouble. Make sure everything is stable before you attempt to convert a JTable to a Table or TableViewer. You will spend some time on these, especially if you have custom editors and viewers.
I have not researched why SWT was designed the way it was. I am guessing there HAD to be a good reason. It would be great if someone had a blog or defense to it's design so I don't have to search for it. Once it's posted I'll remove these lines since they have no relevance to the question.
Addition
I want to add that since you have an existing product I assume works. The best piece of advice I can give you is to never let your code get into a state that it cannot compile and run. If you work on your conversion and whatever you check in always runs and executes (despite the visual differences between SWT/AWT/Swing) you will save yourself many headaches in the long run. The worst thing you can do is try to tackle this all at once and get your code in an unstable state for weeks at a time.
I would suggest importing it into a WindowBuilder project, as WindowBuilder gives you the ability to parse existing code and create a GUI mock-up, then morph components to either SWT or Swing.
If you're thinking of using a mix of SWT and Swing in the same application, this Eclipse Corner Article will be immensely useful.
We are preparing the same step: Swing to SWT/JFace. First we try to determine the bottlenecks: reimplement special components derived from JComponent with SWT/JFace, search for a replacement of JIDE docking (we want to use SWT/JFace, not RCP to avoid too much hassle). The worst thing we already imagine is, that in Swing you could create components and adding it later to the parent. With SWT this is not possible: the parent component must be passed as a reference to the child component's constructor. This will require major refactoring in the Swing application before using SWT.
Frankly, we rate the conversion a very heavy change, because we expect the time where nothing can be compiled as quite long. We try to decrease this time by preparing everything as good as possible, but we'll see how good it will work.
Update from April 6th 2011:
We now refactored our Swing application to always create components with their parent (as in SWT). Our subclasses of JFrame and JDialog got refactored to just have a JDialog instance to make it easier to switch to SWT's Shell. In parallel, we rewrite sophisticated components in SWT.

Turn photoshop design into Java GUI

I can't seem to find anybody who has done or posted something like this; Essentially I want to design my own UI in photoshop and then slice down the images to use it in a Java application. Essentially coding in the PSD file as the GUI. Is this possible? If so, can anybody lead me in the right direction?
I'm not sure what editor to use for this sort of stuff. I am using the Eclipse IDE and I know there is a Visual Editor but, I already have the actual design for every component in a PSD file. All I want to do is to start incorporating this into the application. Thanks.
It depends on how far your design goes. If you simply want to have normal Swing components on top of your image this is easy. Convert your PSD into (for example) PNG, create a custom JPanel subclass that loads the image and overwrite the paintComponent() method to draw the image instead of the normal background. All child components can then be set to be transparent with setOpaque(false). This puts your image into the background and puts the components float on top of it.
If you want to change how individual components look, its a lot more work. You basically need to implement a new Look&Feel for Swing. I wouldn't recommend going that route, unless you really have to, we are talking about weeks of work here, and it requires a lot of testing to really make it work properly on all platforms.
Alternately, there are already tons of custom Look&Feels available, I suggest you take a look at some freely available ones (just google "java look and feel"). Many of them can be customized to some degree (how much depends on the actual implementation, so take a close look at the source/documentation for each of them).
You might want to take a look at NetBeans which has a Swing GUI Builder. You would have to redraw your components there, and then write all the code to process the events. It is sometimes good to start with that, though often times it is less frustrating to lay them out with code by hand as it can difficult to make changes in code and have the builder keep up. There is nothing I know that will let you start from a photoshop image and proceed to building a GUI. Sounds like a good project to make someone rich. :-)

Java UI designer + framework similar to visual studio (drag and drop, floating controls)

I'm looking for a Java UI designer allowing me to drag and drop controls directly to the design surface in a floating mode (without the hassle of north, south etc that comes with SWT). Is there any such tool?
Also, I'm only interested in tools offering a trial version.
EDIT: I'm only interested in solutions allowing me to drag/drop items regardless of panels margin, LayoutManager stuff etc. The position should preferably be just relative to the window margin.
Thanks in advance
You can use NetBeans to design your GUI. Instead of messing with Layout Managers, just use the "Absolute" layout. It will put the UI Components exactly where you drop them, pixel for pixel.
Eclipse has a free visual editor called VEP. See http://www.eclipse.org/vep/
Instantiations has a very nice set of tools with a trial version:
http://instantiations.com
Note that for any visual designer, you should know how layout managers work to use them properly (and make sure your UI expands/contracts/adapts to font/locale properly). If you just use absolute placement, things can get cropped, for example.
See http://developer.java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/ for my article on layout management to get a feel for how to use things like North, South. It only covers the original five Java layout managers, but describes why you need them and how you can nest them.
I recommend JFormDesigner, which has support for "Free Design". From
http://www.jformdesigner.com/doc/help/layouts/grouplayout.html:
The goal of the group layout manager
is to make it easy to create
professional cross platform layouts.
It is designed for GUI builders, such
as JFormDesigner, to use the "Free
Design" paradigm. You can lay out your
forms by simply placing components
where you want them. Visual guidelines
suggest optimal spacing, alignment and
resizing of components.
It has a trial version and is very easy to use.
Netbeans has a drag and drop module called Matisse: http://www.netbeans.org/kb/articles/matisse.html

Categories

Resources