Perdorimi i klases BorderLayout

 Me teper rreth “Layout Managers”

•        Layout manager –    Kontrollon madhesine dhe pozicionimin e komponenteve brenda nje objekti Container. –    Percakton si pozicionohen ose percaktojne madhesine elementet brenda tij. –    Eshte nje interface qe ben pjese ne Java SDK

•     I pozicionon komponentet ne menyre qe te mos mbulojne njeri tjetrin   –    Pershtat komponentet brenda ne Container

•     Cdo komponent qe vendoset brenda nje Container mund te jete vete Container.

•     Mund te caktojme nje layout manager brenda nje layout manager

•        Layout managers te siguruar nga platforma JAVA –    FlowLayout dhe GridLayout –    BorderLayout dhe CardLayout –    GridBagLayout dhe BoxLayout   Perdorimi i BorderLayout

•        BorderLayout manager –    Veçoria default per te gjithe panelet e permbajtjes –    Perdoret ne nje konteiner qe ka 5 ose me pak komponente –    Komponentet mbushin ekranin ne 5 zona:

•     North

•     South

•     East

•     West

•     Center

 


     //Shembull:
import javax.swing.*;
import java.awt.*;
public class JDemoBorderLayout extends JFrame
{
   private JButton nb = new JButton("North Button");
   private JButton sb = new JButton("South Button");
   private JButton eb = new JButton("East Button");
   private JButton wb = new JButton("West Button");
   private JButton cb = new JButton("Center Button");
   private Container con = getContentPane();
   public JDemoBorderLayout()
   {
      con.setLayout(new BorderLayout());
      con.add(nb, BorderLayout.NORTH);
      con.add(sb, BorderLayout.SOUTH);
      con.add(eb, BorderLayout.EAST);
      con.add(wb, BorderLayout.WEST);
      con.add(cb, BorderLayout.CENTER);
      setSize(400, 150);
   }
   public static void main(String[] args)
   {
      JDemoBorderLayout frame = new JDemoBorderLayout();
      frame.setVisible(true);
   }
}

  Perdorimi i FlowLayout

•        FlowLayout manager –    Pershtat komponentet ne rreshta ne te gjithe gjeresine e Container –    Kur ju shtoni nje Component:

•     Ai vendoset pas komponenteve te tjere ne rresht

•     Nese mbushet rreshti aktual, komponenti vendoset ne rresht te ri –    Cdo Component mban madhesine e preferuar.  

•        Ju mund te perdorni 3 konstante per te pozicionuar  komponentet brenda ne nje Container: –    FlowLayout.LEFT –    FlowLayout.CENTER –    FlowLayout.RIGHT

•        Nese pozicionimi nuk specifikohet, komponentet vendosen te qenderzuar •        invalidate() - Kjo metode thirret automatikisht kur ndryshon ndonje informacion qe ka lidhje me layout (psh kur shtohen ose pozicionohen komponentet ).

•        validate() –    Ben qe komponentet te rivendosen bazuar ne layout-in e ri te vendosur. 


     // Shembull:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDemoFlowLayout extends JFrame implements ActionListener
{
   private JButton lb = new JButton("L Button");
   private JButton rb = new JButton("R Button");
   private Container con = getContentPane();
   private FlowLayout layout = new FlowLayout();
   public JDemoFlowLayout()
   {
      con.setLayout(layout);
      con.add(lb);
      con.add(rb);
      lb.addActionListener(this);
      rb.addActionListener(this);
      setSize(500, 100);
   }
   public void actionPerformed(ActionEvent event)
   {
      Object source = event.getSource();
      if(source == lb)
         layout.setAlignment(FlowLayout.LEFT);
      else
         layout.setAlignment(FlowLayout.RIGHT);
      con.invalidate();
      con.validate();
   }
   public static void main(String[] args)
   {
      JDemoFlowLayout frame = new JDemoFlowLayout();
      frame.setVisible(true);
   }
}