Java Layout Manager Advice [closed] - java

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've got the idea of how I want my graphics to look but I've been messing around with LayoutManagers for a while and can't seem to find a combination that works well.
Here's the setup:
1 JFrame containing 2 JScrollPanes. ScrollPane1 gets 30% of the JFrame vertical space. ScrollPane2 gets 70% of the JFrame vertical space.
Each JScrollPane has: 1 JLabel centered in the middle at the top of the ScrollPane, 1-4 JButtons centered at the bottom of the scrollpane, and many JCheckBoxes somewhere in the middle of each scrollpane.
Ideally it would look like below:
http://i.imgur.com/f7KsC.jpg
My question is: What layout managers would you use for the JFrame and each JScrollPane?
EDIT: All external toolkits must go through our company's legal division before they can be incorporated into our projects. I would like to stick to internal Java libraries.
EDIT 2: Finished!! Here's the final setup:
http://i.imgur.com/5ndjx.png
What I learned is that it's important to keep compartmentalizing in Java. I was using too few containers for all of my objects hoping they would fit cleanly on the Frame. So I started using way more Panels and Layout Managers and it came out BEAUTIFUL. Looks perfect. Thanks everyone for the help.

IMHO, I would make the content pane of the container a JSplitPane instance.
The upper half would consist of three layered JComponent instances and use the BoxLayout manager with a Y_AXIS alignment. The top layer would use the FlowLayout manager. The middle layer would consist of several juxtaposed JComponent instances, where each would use the BoxLayoutmanager with a Y_AXIS alignment. And of course, the layer itself would use the FlowLayout manager. The bottom layer would consist of several juxtaposed JComponent instances and use the FlowLayout manager.
The lower half would be the exactly the same as the upper half, and therefore, consider encapsulating all this logic within a single custom component.
For more information, see Using Layout Managers.

I would be inclined to use MigLayout at pretty much every step.

Related

Can I Move Swing Components in CardLayout? [duplicate]

This question already has an answer here:
Positioning component inside card layout
(1 answer)
Closed 5 years ago.
I have read this SO Question regarding this problem, but I am still a little lost on how to freely move and position swing components. I am new to Swing, and so I am still learning the ins and outs of it. I have read other documentation and articles online, but I have yet to see anything that shows how to move components around. I have even tried things set as setBounds, but it has been to no avail.
What are some ways I can position components in the CardLayout? Any help is appreciated.
Your question doesn't make sense, in that it's asking something akin to, can I move an elevator sideways. No, you can't. A CardLayout is for swapping components, and that's all it can do. The JPanel that holds it is given a preferredSize by the layout determined by the maximal preferred sizes of the contained components. This layout is not for positioning, translating, or scaling components, and for these functionalities you'd need to use other layout managers. Fortunately you can nest panels, each using its own layout manager and thereby move or translate components as your use of layouts see fit.
For more detailed answer, consider creating and posting your minimal example program.
And in fact, the question that you linked to answers this much more comprehensively, and so I've made this answer a community wiki and have closed your question as a duplicate. I strongly urge you to read or re-read the Layout Manager Tutorial.

Java Simple Layout [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
What is the best library to use in Java for a simple layout.
Here is an image of what I am wanting to have on the form.
I am looking for the most simplest layout library, that also has good positioning features.
See the Nested Layout Example for ideas about how to combine layouts to create the required layout.
I'm assuming that you want to use Java Swing since you named your components with a J.
The outer JPanel could use a BorderLayout. The JList would be inside of a JScrollPane. The JScrollPane would be in the center, the radio button panel would be in the west, and the Jbutton would be in the south.
The radio button panel would use a GridBagLayout to get the buttons to be the same size and so you can specify the pixel spacing (insets) between the radio buttons. This panel would be placed inside another JPanel with a FlowLayout to keep the radio buttons from spreading out and taking up the whole panel.
Read this interesting article, Sudoku Solver Swing GUI, for more information on how to layout a Swing GUI.
I would try it with Swing. Or is that too complex?
There are total 8 layout managers in JAVA library.
There is also one free open source which you can use is MigLayout.
Its Easy to use yet very powerful Java Swing, JavaFX 2 and SWT layout manager,
Use Swings.And IDE you can prefer NetBeans as in netbeans you can drag and drop to create UI,which is quite easy compare to coding

about preparing the map of Risk game with swing in java [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
i want to start coding a game project which is called "Risk" and my first aim is build the map correctly. So logically, each territory should be a JButton but JButton's are rectangular oriented. Moreover, i know that every territory should be a component so i can use mouse event listeners for each of them. well my question is
should i try to draw each territory with using coordinates, lines, shapes etc ? or
is there any way to draw and combine each territory regularly ?
On the other hand, this is the link for the map of the game.
Map of Risk
try to make fixed territories, so you mustn't have headaches with resizing your actual territory, only change the color of the territory you occupied recently, like in Dune2 was, if you know that game. And I think, definitively you should, and put that jbutton under the numbers on your map (or what will be definitively better, if you replace numbers with territory name and you'd put that button under that). I hope, my answer answered your doubts :)
I feel like it's going to be a lot of work. The easy way out would be to just put JButtons under the numbers.
If you still feel inclined to make irregularly shaped clickable areas, I suggest creating instances of Polygon (java.awt) for each country. They are made using arrays of x and y points that define the corners. Conveniently enough, there is a Polygon.contains(x, y) method that lets you know if (x, y) is in your polygon. If you use a larger JPanel that covers the entire map and get the mouse location relative to the JPanel, you can notify each country whether or not the mouse is inside it.

Best Swing Solution for Schedule Event Calendar [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Friends!
I want to create a simple schedule event calendar like this one
Question: What can i use in Swing/AWT hiearchy in order to have such flexible grid.
P.S I was trying to do some solution in JTable direction with Custom CellRenderers but it was ugly. Maybe it can be something like JPanel-in-JPanel solution? What do you think?
This is not a simple solution and you have any number of options...
Because the content can expand over multiple rows, JTable isn't really a viable solution (there's probably any number of ways to do it, but each will become more complicated over time...and any solution I've seen doesn't take into account the current Look and Feel).
But if you're interested, you could take a look at
spantable (haven't used)
JTable Examples (haven't used)
You other choice would be to create a custom component capable of rendering the data model.
I, personally, would focus on an individual column, allowing it to be it's panel. With a custom layout manager, you could layout additional components based on the requirements of the data model.
Once you have that figured out, you would be able to expand the concept to allow for multiple rows.
This allows you greater flexibility in how the individual components are laid out and rendered, but is quite complex.
I would take a look at How to use Scroll Panes so you can see how row and column headers work ;)

What is the use of Container in Swing? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What is the use of Container in Swing?
A Swing Container is a component that holds or wraps-up other components. It aids with grouping related components together in the GUI. There are a lot of resources on the web that explain how to use Containers.
http://java.sun.com/products/jfc/tsc/articles/containers/index.html
http://oreilly.com/catalog/jswing/chapter/ch08.pdf
A container in Swing is something that holds other components.
A container is responsible to displaying the components according to your layout.
If a button is placed on the top left corner, every time the window is re-sized, the button will still be on the top left corner. This is because the container is containing the button and at the same time containing its layout position. That is why it's container.setLayout()
and container.add()
In Java Swing, a lot of components can be a container. A JButton can be a container, and so can a JLabel.
JPanel is also a container, and anything that extends those three can also be a container.
Well ... Containers are used to contain other widgets, and to help arrange them in a way that suits the design of the UI.
For instance, JPanel is a general-purpose container. Together with a LayoutManager, you can get many different layouts of widgets.
Container can has other compoments or container. it can be three level.
top level .such as JFrame, JDialog,JApplet.these containers can't be contained.
immediate container ,such as Jpanel we ofen use
low level. So this is what we know as low level components.

Categories

Resources