![]() The dummy JLabel in each row gets bigger by half the size of the JButtons. PLAIN, 14)) contentPane.add(new JButton(Button 1)). The main JPanel uses a GridLayout of (0, 1) to create the staggered effect. FlowLayout puts components in a row, sized at their preferred size. setBounds(int x-coordinate, int y-coordinate, int width, int height) The frame’s layout manager can be null to manually set the size and position. setSize(600,80) // set the JFrames size, notice it is not very high frame. The second two arguments are width and height used to set the size of the component. for FlowLayout public class Ch121 // create a simple GUI of 6 JButtons. The row is created with a row JPanel with a FlowLayout, using a dummy JLabel and the button row JPanel. The first two are the x and y coordinate used to position the component. 18 is the font size (using the same numbering system for font size as Microsoft Word). Font.BOLD means bold text (as opposed to PLAIN or ITALIC). The buttons on each row are created in a JPanel with a GridLayout. JButton button new JButton('Click here') tFont(new Font('Arial', Font.BOLD, 18)) Arial is obviously the name of the font used. ![]() Source: (RoundButton.java) import java.awt.* import .* import javax.swing.* import order to do this, I had to use a combination of Swing layouts. setSize (100, 26) // Add the button to the window: jPanel1.add(b1) //Repaint the Panel to make visible jPanel1. ![]() Use FlowLayout because it's quick and easy. BorderLayout, BoxLayout, FlowLayout, GridBagLayout, GridLayout. ![]() When a container size is changed (eg, when a window is resized), FlowLayout recomputes new positions for all components subject to these constraints. Here is an example java program that demonstrates how to create a round JButtons. FlowLayout() : Creates an instance with the centered alignment and with the default horizontal and vertical space of 5 pixels between the components. // Create a new button: JButton b1 new JButton('ok') // Set the location and size of the button: b1. arranges components from left-to-right and top-to-bottom, centering components horizontally with a five pixel gap between them. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |