java - Leave small space between buttons when using GridLayout -


I'm trying to create a toolbar that will go to the top of all the pages of my java swing application.

I am creating a JPNL that has a series of separate JPNLs (Container) Each JPNL (container) has a North and South component or just one answer component, which is set using GridLayout.

My problem is, I want a small gap between the components of the North and the South, but I '

one of the following for the one of the containers Example:

  public static zero subscriber () {last JFrame frame = new JFrame ("nested layout example"); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Japanese container 1 = new zpn (); Container 1. Set Layout (New Grid Layout (2,1)); Jebton ButtonDierre = New Jebton ("Diary"); ButtonDi .Set Refitted Size (New Dimension (140, 25)); Pocket button case = new pocket ("car"); ButtonCars.setprofile size (new dimension (140, 25)); Container 1. Ad (Buttony, Border Layout, North); Container1.add (Button, Border Layout. South); Frame.setContentPane (container1); Frame.pack (); Frame.setVisible (true); }  

I'm trying to create a toolbar At the top of all pages in the Java Swing app

Why not use it? See

I am creating JPNL with a series of separate JPNL (container) in it, each JPNL (container) has a north and south component or just one answer component , Which is set using gridbout layout.

Based on your code, none of these statements are correct: you are adding buttons (not panel) and you are not using:

  JPNL container 1 = new JPNL (); Container 1. Set Layout (New Grid Layout (2,1)); // Grid Layout, Jebton ButtonDierre = New Pocket ("Diary"); // button here buttonDearetRimated size (new dimension (140, 25)); Pocket button case = new pocket ("car");  

In addition to this, you are using the border layout constraints, which can be found in the GridLayout or GridBagLayout :

  container 1.add (buttonDist, border layout. North); Container1.add (Button, Border Layout. South);  

You should keep an eye on the whole lesson to learn about layout managers and how they all work.

In addition to this

is as informed by Java NICC, because Java 1.4 border layout new constants are encouraged very much :

  PAGE_START PAGE_END LINE_START LINE_END CENTER  

from tutorial (bold text mine):

With the release of JDK 1.4 Previously, different names of different areas were different, with the compass points (for example, BorderLayout.NORTH in the top area New) we Wardiayr versions of constants went to use their examples. Constants Using our examples is a priority because they are standard and are capable of adjusting programs which adjust languages ​​with different orientations.

update

Okay, your question has been edited to say that you actually have GridLayout it is easy to answer that you can specify horizontal and vertical intervals between components, or by the creator of the class: or setHgap () and setVgap () Methods:

  JPNL container 1 = new zpinal (new grid layout (2, 1, 8, 8)); // or gridlout layout grid layout = new grid layout (); GridLayout.setRows (2); GridLayout.setColumns (1); GridLayout.setHgap (8); GridLayout.setVgap (8); Japanese container 1 = new zip (grid layout);   

When you add the button to the container1 panel, do not forget to remove the border layout barriers, because they will be ignored :

Container 1.add (ButtonDisk); Container1.add (buttonCars);

You may also want to take a look at this topic:


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -