Java Layout Manager tips [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I created a small program which is shown in the link. And I used
absolute layout. But I want to try other layouts. Are there any alternative layouts to use apart from absolute layout ?
Here is the link

As a different opinion, I wouldn't recommend GridBagLayout. It is the most flexible so you can do pretty much anything with it but it is pretty hard to use. A simpler way is to use a composed approach, meaning multiple panels in your main UI where each panel has its own layout. For example, for the two top components you can use a vertical BoxLayout and for the bottom part you can use a FormLayout
But the point is, it is better IMO to mix and match layouts than to use one single super flexible layout for everything. Check this link for more info. They mention what I recommended:
Layout Managers are often mixed together in a single frame or dialog,
where a top level container has its own Layout Manager (often a
BoxLayout or BorderLayout), and smaller parts use their own layout,
completely independent of the others.
Another nice tip is to use a GUI builder such as Eclipse's WindowBuilder or Netbean's Matisse; that way you don't design UIs in code, which is pretty abstract

Use gridbaglayout. To properly use it, read first about gridbagconstraints.

Related

how to create jframe with re sizable components [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm creating a java application.there I want to keep jframe in maximized state.and I want to use it many of monitors that have different screen size.and I want to components in jframe to resize with jframe.also I need to add image to the background of the frame.that image also should resize with the jframe. how to do that?
Layout managers, layout managers, layout managers
Start by taking a look at
A Visual Guide to Layout Managers
How to Use Various Layout Managers
Using Layout Managers
You might also want to have a look at Full-Screen Exclusive Mode API, depending on what you're hoping to achieve
also I need to add image to the background of the frame.that image also should resize with the jframe. how to do that?
Java: maintaining aspect ratio of JPanel background image
How to set a background picture in JPanel
How do I resize images inside an application when the application window is resized?
I see lots of searching and research in your future.

Custom JTabbedPane [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Looking to customise my JTabbedPane to look something like the below:
As you can see it's quite a simple design so shouldn't be too difficult to achieve? I've read a bit on changing Look and Feel but got a bit lost with the wealth of information and options there. Anyone any useful pointers for me?
Changing the look and feel of your complete application is one of the easiest ways to do it. Here is the list (with screen shots, how to use and download links) of different looks and feels for java swing. Use one of them to get some great looks and feels for your swing application.
P.S. Simply put the code into your main method.
As you can see it's quite a simple design so shouldn't be too difficult to achieve?
Creating a custom UI is always a problem. You need to implement the change for all LAF's you intend to support.
You would start by looking at BassicTabbedPaneUI. There you will find the various paintTab...(...) methods. Then you need to look at your LAF, for example the MetalTabbedPaneUI to see if the LAF uses the default implementation or does a custom implementation. Once you know this you override the appropriate class and implement your custom painting code.
Then in your code you have something like:
JTabbedPane tabbedPane = new JTabbedPane(...);
tabbedPane.setUI( new MyCustomTabbedPaneUI() );

Java JFrame Item Positions/Sizes [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am aware of the methods and coding required to set a JFrame item's position and size, but I need a bit of help knowing how to correctly size and position items. Is there a way to use another JFrame API/method to separate the window into sections to make positioning items easier? What are the maximum values for height and width? How do I set a button to an average size? If you have some experience with JFrames, please give me some info about this to help me understand how to position and size JFrame items.
You shouldn't be worrying about pixel perfect positioning of components. Swing wasn't meant to be used as such. Being a language that is meant to be run on many different platforms, the GUI library should be flexible as such. To maintain the flexibility, layout managers are introduced. You should be using these layout managers do the sizing and positioning for you.
You can see a visualization of how each work at A Visual Guide to Layout Managers. With these layout managers, you'll want to learn (at the very least)
Which ones respect preferred size and which ones don't.
how each ones are represented visually.
How to create white space, using gaps, empty borders, struts
How use use nested containers with different layout managers to get your desired result.
It may intimidating with all the different possibilities, but like learning anything new, take it one step at a time. Go through each tutorial for each layout manager.

how do i set the size of my window gridbaglayout [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I'm using gridbaglayout and I want my window to be 700 x 500 always. I also was my JButtons to be the exact same size but if the word inside them is longer they get longer and I can't have this. How can I do this? Please help me with good code I been trying for hours.
I tried to do frame.setSize and panel.setSize but neither work and I need this fast! Please help!
The basic answer is, you don't. That's not the point of any layout manager.
A layout manager simple makes decisions about how best to layout it's children based on the sizing hints that they provide.
Remember, while it might look great on your screen, the next computer you run it on may make it look like crap.
If you "must" define the size of anything, then you need to override the getPreferredSize method of your component and return an appropriate size hint.
Having said that, I wouldn't do this for components like JButton (or actually anything other than JPanel and JComponent), the way they calculate their sizes are complicated and best left alone.
You can modify the size of components through the use of Borders and, in the case of GridBagLayout, Insets and modifying the GridBagConstraints properties.
Have a closer look at How to Use GridBagLayout for some more ideas

how should I design changing GUIs? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need a panel with text fields a,b,c for project AA.
I need another panel with text fields a,b,d,e,f for project BB.
In future I will definitely need another panel with text fields a,b,d,y,z for project CC.
Again in future I may need another panel with... etc.
a and b text fields are common for all projects and d is common for BB and CC.
Layout of common fields may differ. Panels include methods such as createComponents, guiLayout, refresh, save, getGUIErrors...
Now, How should I design my panels? What about inheritance? Is defining a common panel including fields a,b and extending it for projects correct? Is it possible to use composition, decorator pattern ?
Of course question can be extended to models and controllers.
thank you .
Now, How should I design my panels? What about inheritance? Is defining a common panel including fields a,b and extending it for projects correct? Is it possible to use composition, decorator pattern ?
While code reuse is generally good, it seems to me you are overcomplicating things here. Why bother with all that work if it is simply to re-use two textfields on a panel. We are talking about two lines of code.
If all your panels look pretty similar, use a decent layout builder and reuse that one (see for example the builder available for the FormLayout of JGoodies).
Next to that, the typical UI layer is pretty thin. Re-use your business side (the models behind the UI) if needed/possible, but do not bother with the UI. In my experience, this lead to much cleaner code.
I have seen too many UIs/panels where the constructor takes a lot of boolean flags to include/exclude certain fields, a bunch of protected methods to provide access to all components (e.g. to disable a certain field on certain conditions), ... in short, a lot of code because in the end no two UIs are the same and you always have to customize.

Categories

Resources