Search code examples
javaswinguser-interfacegrid-layoutflowlayout

Gridlayout and Flowlayout. what are these?


i would ask a question.

WHAT and WHAT are the DIFFERENCE of FLOWLAYOUT and GRIDLAOUT in java.

advantages and disadvantages (if theres).

because my prof says about these terms to build a GUI in java.

and all i know is the JOption.

so what are these terms. thank you. hope anyone help me with these.


i google it , but no luck so this my last resort.


Solution

  • On the chance that what you need is a high-level description (which the tutorials, good and useful as they are, don't always provide):

    GridLayout and FlowLayout are both layout managers.

    A layout manager positions components within a container (such as a JPanel or a JFrame). Different layout managers do this in different ways, with different rules, for different purposes, but they all have that in common. The idea is that the programmer adds components to a container, and the layout manager determines their position.

    Since top-level containers are (most?) often resizable by the end-user, one of a layout manager's primary jobs is to position components according to its rules when the container is larger or smaller than the "natural" size one would get after packing the components. When studying layout managers, this is one of the things you learn to pay close attention to, so that the UI behaves the way you want it to. Believe me, you don't want to write the code to handle all the possible circumstances for resize yourself.

    GridLayout has rules that positions the components in a grid where each cell is the same size and all are stretched equally.

    FlowLayout has rules for positioning components one after another, horizontally (and maybe vertically, I don't remember offhand), and 'wrapping' them if the container is made too small to contain them.