![]() ![]() FlowLayout.LEFT is the field available for alignment. In the above code, setAlignment(FlowLayout.LEFT) will set the panel layout alignment to left.For this to work, the particular button is added on the window panel and on the click event of that button, the layout will be set to Left.When we click on a button named “left” for left alignment, the buttons on the window-pane should be aligned to the left. ![]() With the setLayout() functions, we are setting the layout as flowlayout.When creating the class instance, we need to see the buttons so adding the buttons to a container in the class constructor itself.In the above code, we had declared 3 buttons with the help of JButton as lb, rb, and cb.L.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) Public void actionPerformed(ActionEvent event) This constructor will align by the specified align field as RIGHT, LEFT or CENTER and also provides the option for adding horizontal gap and the vertical gap between components.įollowing is an example of flow layout in java:.FlowLayout(int align, int horizontalGap, int verticalGap): Constructs a FlowLayout with a given alignment and with a given horizontal and vertical gap between the components.FlowLayout(int align): Constructs a FlowLayout with a given alignment with 5 pixels gap between the components.FlowLayout(): Constructs an instance of FlowLayout as center-aligned and with 5 pixels gap between the components.setTitle(String text): Sets the title of the container with the given text.addLayoutComponent(): Adds the particular component to the layout.getAlignment(): Gets the alignment of the layout of the container. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |