Tabnine Logo
BorderLayout
Code IndexAdd Tabnine to your IDE (free)

How to use
BorderLayout
in
java.awt

Best Java code snippets using java.awt.BorderLayout (Showing top 20 results out of 12,294)

Refine searchRefine arrow

  • JPanel
  • Container
  • JFrame
  • Window
  • JButton
  • JLabel
  • JComponent
origin: pedrovgs/AndroidWiFiADB

private void createNoDevicesPanel() {
 panelNoDevices = new JPanel(new BorderLayout());
 JLabel labelNoDevices = new JLabel(NO_DEVICE_CONNECTED);
 labelNoDevices.setHorizontalAlignment(SwingConstants.CENTER);
 panelNoDevices.add(labelNoDevices);
}
origin: pmd/pmd

private void init() {
  JTextArea errorArea = new JTextArea();
  errorArea.setEditable(false);
  errorArea.setText(exc.getMessage() + "\n");
  getContentPane().setLayout(new BorderLayout());
  JPanel messagePanel = new JPanel(new BorderLayout());
  messagePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory
      .createTitledBorder(BorderFactory.createEtchedBorder(), NLS.nls("COMPILE_ERROR.PANEL.TITLE"))));
  messagePanel.add(new JScrollPane(errorArea), BorderLayout.CENTER);
  getContentPane().add(messagePanel, BorderLayout.CENTER);
  JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  okBtn = new JButton(NLS.nls("COMPILE_ERROR.OK_BUTTON.CAPTION"));
  okBtn.addActionListener(this);
  btnPane.add(okBtn);
  getRootPane().setDefaultButton(okBtn);
  getContentPane().add(btnPane, BorderLayout.SOUTH);
  pack();
  setLocationRelativeTo(getParent());
  setVisible(true);
}
origin: apache/shiro

public void afterPropertiesSet() throws Exception {
  ClassPathResource resource = new ClassPathResource("logo.png");
  ImageIcon icon = new ImageIcon(resource.getURL());
  JLabel logo = new JLabel(icon);
  saveButton = new JButton("Save Value");
  saveButton.addActionListener(this);
  refreshButton = new JButton("Refresh Value");
  refreshButton.addActionListener(this);
  JPanel valuePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
  valuePanel.add(valueField);
  valuePanel.add(saveButton);
  valuePanel.add(refreshButton);
  methodPanel.add(secureMethod3Button);
  frame = new JFrame("Apache Shiro Sample Application");
  frame.setSize(500, 200);
  Container panel = frame.getContentPane();
  panel.setLayout(new BorderLayout());
  panel.add(logo, BorderLayout.NORTH);
  panel.add(valuePanel, BorderLayout.CENTER);
  panel.add(methodPanel, BorderLayout.SOUTH);
origin: pmd/pmd

public GUI() {
  frame = new JFrame("PMD Duplicate Code Detector (v " + PMDVersion.VERSION + ')');
  menuBar.add(fileMenu);
  menuBar.add(viewMenu);
  frame.setJMenuBar(menuBar);
  JButton browseButton = new JButton("Browse");
  browseButton.setMnemonic('b');
  browseButton.addActionListener(new BrowseListener());
  goButton = new JButton("Go");
  goButton.setMnemonic('g');
  frame.getContentPane().setLayout(new BorderLayout());
  JPanel topPanel = new JPanel();
  topPanel.setLayout(new BorderLayout());
  topPanel.add(settingsPanel, BorderLayout.NORTH);
  topPanel.add(progressPanel, BorderLayout.CENTER);
  setProgressControls(false); // not running now
  frame.getContentPane().add(topPanel, BorderLayout.NORTH);
  frame.getContentPane().add(resultsPanel, BorderLayout.CENTER);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.pack();
origin: stackoverflow.com

 JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(200, 200);

// create the status bar panel and shove it down the bottom of the frame
JPanel statusPanel = new JPanel();
statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
frame.add(statusPanel, BorderLayout.SOUTH);
statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 16));
statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
JLabel statusLabel = new JLabel("status");
statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
statusPanel.add(statusLabel);

frame.setVisible(true);
origin: stackoverflow.com

 public static void main(String args[]){
  JFrame f = new JFrame();
  f.setLayout(new BorderLayout());
  final JPanel p = new JPanel();
  p.add(new JLabel("A Panel"));
  f.add(p, BorderLayout.CENTER);

  //create a button which will hide the panel when clicked.
  JButton b = new JButton("HIDE");
  b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        p.setVisible(false);
    }
  });

  f.add(b,BorderLayout.SOUTH);
  f.pack();
  f.setVisible(true);
}
origin: stackoverflow.com

private JSpinner gravitySpinner;
private JPanel mainPanel = new JPanel();
 mainPanel.setLayout(new BorderLayout());
 draw = new DrawingArea();
 mainPanel.add(draw, BorderLayout.CENTER);
 userInt = new JPanel();
 mainPanel.add(userInt, BorderLayout.NORTH);
 b1 = new JButton("Start");
 b2 = new JButton("aaa");
 b1.addActionListener(new ActionListener() {
   @Override
 SwingUtilities.invokeLater(new Runnable() {
   public void run() {
    JFrame window = new JFrame("Ball");
    window.add(new StartingPoint().getMainPanel());
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.pack();
    window.setLocationRelativeTo(null);
    window.setVisible(true);
origin: iluwatar/java-design-patterns

private void setup() {
 setLayout(new BorderLayout());
 JPanel panel = new JPanel();
 add(jl, BorderLayout.SOUTH);
 add(panel, BorderLayout.CENTER);
 panel.setLayout(new GridLayout(6, 2));
 panel.add(new JLabel("Name"));
 panel.add(jtFields[0]);
 panel.add(new JLabel("Contact Number"));
 panel.add(jtFields[1]);
 panel.add(new JLabel("Address"));
 panel.add(jtAreas[0]);
 panel.add(new JLabel("Deposit Number"));
 panel.add(processButton);
 clearButton.addActionListener(e -> {
  for (JTextArea i : jtAreas) {
   i.setText("");
 processButton.addActionListener(e -> {
  Order order = new Order(jtFields[0].getText(), jtFields[1].getText(), jtAreas[0].getText(), jtFields[2].getText(),
    jtAreas[1].getText());
origin: stanfordnlp/CoreNLP

private void doEncodingPrompt(final String encoding, final String oldEncoding) {
 final JPanel encodingPanel = new JPanel();
 encodingPanel.setLayout(new BoxLayout(encodingPanel, BoxLayout.PAGE_AXIS));
 JLabel text = new JLabel("<html>A head finder or tree reader was selected that has the default encoding " + encoding
   + "; this differs from " + oldEncoding + ", which was being used. If the encoding is changed, all newly loaded" +
   "treebanks will be read using the new encoding. Choosing an encoding that is not the true encoding of your tree " +
   "files may cause errors and unexpected behavior.</html>");
 text.setAlignmentX(SwingConstants.LEADING);
 JPanel textPanel = new JPanel(new BorderLayout());
 textPanel.setPreferredSize(new Dimension(100,100));
 textPanel.add(text);
 fileFilterDialog.setMessage(encodingPanel);
 JButton[] options = new JButton[3];
 JButton useNewEncoding = new JButton("Use " + encoding);
 JButton useOldEncoding = new JButton("Use " + oldEncoding);
 JButton useAnotherEncoding = new JButton("Use encoding...");
origin: checkstyle/checkstyle

final JButton openFileButton = new JButton(new FileSelectionAction());
openFileButton.setMnemonic(KeyEvent.VK_S);
openFileButton.setText("Open File");
});
final JLabel modesLabel = new JLabel("Modes:", SwingConstants.RIGHT);
final int leftIndentation = 10;
modesLabel.setBorder(BorderFactory.createEmptyBorder(0, leftIndentation, 0, 0));
final JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 2));
buttonPanel.add(openFileButton);
buttonPanel.add(reloadFileButton);
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(buttonPanel);
mainPanel.add(modesPanel, BorderLayout.LINE_END);
origin: stackoverflow.com

final JFrame frame = new JFrame("Nested Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel gui = new JPanel(new BorderLayout(5,5));
gui.setBorder( new TitledBorder("BorderLayout(5,5)") );
plafComponents.add(plafChooser);
plafComponents.add(pack);
gui.add(plafComponents, BorderLayout.NORTH);
JPanel dynamicLabels = new JPanel(new BorderLayout(4,4));
dynamicLabels.setBorder(
  new TitledBorder("GridLayout(0,2,3,3)") );
JButton addNew = new JButton("Add Another Label");
    labels.add( new JLabel("Label " + ++labelCount) );
g.fillRect(0,0,200,200);
ImageIcon ii = new ImageIcon(bi);
JLabel imageLabel = new JLabel(ii);
frame.setContentPane(gui);
frame.pack();
origin: chewiebug/GCViewer

/**
 * @param gcResource resource to be tracked
 */
public GCModelLoaderView(GCResource gcResource) {
  super(new BorderLayout());
  setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  JPanel parserInfo = new JPanel(new FlowLayout(FlowLayout.LEFT));
  progressBar = new JProgressBar(0, 100);
  progressBar.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  progressBar.setVisible(true);
  progressBar.setValue(0);
  progressBar.setStringPainted(true);
  cancelButton = new JButton(new SquareIcon());
  cancelButton.setActionCommand(CMD_CANCEL);
  cancelButton.addActionListener(this);
  messageLabel = new JLabel();
  messageLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  messageLabel.setVisible(false);
  parserInfo.add(progressBar);
  parserInfo.add(cancelButton);
  parserInfo.add(messageLabel);
  add(parserInfo, BorderLayout.NORTH);
  JTextArea textArea = textAreaLogHandler.getTextArea();
  textArea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  JScrollPane textAreaScrollPane = new JScrollPane(textArea);
  textAreaScrollPane.setPreferredSize(new Dimension(700, 500));
  add(textAreaScrollPane, BorderLayout.CENTER);
  setGCResource(gcResource);
}
origin: deathmarine/Luyten

protected JDialog createDialog(Component parent) {
  Frame frame = parent instanceof Frame ? (Frame) parent
      : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
  JDialog dialog = new JDialog(frame, ("Select Font"), true);
  Action okAction = new DialogOKAction(dialog);
  Action cancelAction = new DialogCancelAction(dialog);
  JButton okButton = new JButton(okAction);
  okButton.setFont(DEFAULT_FONT);
  JButton cancelButton = new JButton(cancelAction);
  cancelButton.setFont(DEFAULT_FONT);
  JPanel buttonsPanel = new JPanel();
  buttonsPanel.setLayout(new GridLayout(2, 1));
  buttonsPanel.add(okButton);
  buttonsPanel.add(cancelButton);
  buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));
  ActionMap actionMap = buttonsPanel.getActionMap();
  actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
  actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
  InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
  inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));
  JPanel dialogEastPanel = new JPanel();
  dialogEastPanel.setLayout(new BorderLayout());
  dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);
  dialog.getContentPane().add(this, BorderLayout.CENTER);
  dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
  dialog.pack();
  dialog.setLocationRelativeTo(frame);
  return dialog;
}
origin: stackoverflow.com

 public static void main(String[] args) {
  JFrame frame = new TestScrollPane();
  JPanel panel = new JPanel();
  JTable table = new JTable();

  panel.setLayout(new BorderLayout());
  panel.add(new JLabel("NORTH"), BorderLayout.NORTH);
  panel.add(new JLabel("SOUTH"), BorderLayout.SOUTH);

  JScrollPane sp = new JScrollPane(table);
  sp.setBorder(BorderFactory.createEmptyBorder());
  panel.add(sp, BorderLayout.CENTER);
  frame.add(panel);

  frame.setVisible(true);
}
origin: stackoverflow.com

  super(new BorderLayout());
  Model model = new Model();
  View view = new View(model);
  Control control = new Control(model, view);
  JLabel label = new JLabel("Guess what color!", JLabel.CENTER);
  this.add(label, BorderLayout.NORTH);
  this.add(view, BorderLayout.CENTER);
  this.add(control, BorderLayout.SOUTH);
private JButton reset = new JButton("Reset");
private Model model;
private ColorIcon icon = new ColorIcon(80, Color.gray);
private JLabel label = new JLabel(s, icon, JLabel.CENTER);
  super(new BorderLayout());
  this.model = model;
  label.setVerticalTextPosition(JLabel.BOTTOM);
  label.setHorizontalTextPosition(JLabel.CENTER);
  this.add(label, BorderLayout.CENTER);
  JPanel panel = new JPanel();
  for (Piece p : Piece.values()) {
    PieceButton pb = new PieceButton(p);
origin: stackoverflow.com

JButton showWaitBtn = new JButton(new ShowWaitAction("Show Wait Dialog"));
JPanel panel = new JPanel();
panel.add(showWaitBtn);
JFrame frame = new JFrame("Frame");
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JPanel panel = new JPanel(new BorderLayout());
panel.add(progressBar, BorderLayout.CENTER);
panel.add(new JLabel("Please wait......."), BorderLayout.PAGE_START);
dialog.add(panel);
dialog.pack();
origin: stackoverflow.com

final JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel l = new JLabel();
        l.setText("Time: " +
            System.currentTimeMillis());
new Thread(t).start();
final JButton b = new JButton("Stop");
b.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e)
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(l, BorderLayout.CENTER);
f.getContentPane().add(b, BorderLayout.SOUTH);
f.setLocation(100, 100);
f.pack();
f.setVisible(true);
origin: stackoverflow.com

private WebEngine engine;
private JFrame frame = new JFrame();
private JPanel panel = new JPanel(new BorderLayout());
private JLabel lblStatus = new JLabel();
  txtURL.addActionListener(al);
  progressBar.setPreferredSize(new Dimension(150, 18));
  progressBar.setStringPainted(true);
  JPanel topBar = new JPanel(new BorderLayout(5, 0));
  topBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
  topBar.add(txtURL, BorderLayout.CENTER);
  topBar.add(btnGo, BorderLayout.EAST);
  JPanel statusBar = new JPanel(new BorderLayout(5, 0));
  statusBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
  statusBar.add(lblStatus, BorderLayout.CENTER);
  statusBar.add(progressBar, BorderLayout.EAST);
  panel.add(statusBar, BorderLayout.SOUTH);
  frame.getContentPane().add(panel);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
origin: wiztools/rest-client

private void initComponents() {
  JPanel jp = new JPanel();
  jp.setLayout(new BorderLayout());
  jta_error = new JTextArea(10, 40);
  jta_error.setEditable(false);
  JScrollPane jsp = new JScrollPane(jta_error);
  jp.add(jsp, BorderLayout.CENTER);
  
  JPanel jp_south = new JPanel();
  jp_south.setLayout(new FlowLayout(FlowLayout.CENTER));
  
  jb_ok = new JButton("Ok");
  jb_ok.setMnemonic('o');
  getRootPane().setDefaultButton(jb_ok);
  jb_ok.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {
      jb_okActionPerformed(event);
    }
  });
  jp_south.add(jb_ok);
  
  jp.add(jp_south, BorderLayout.SOUTH);
  this.setContentPane(jp);
  pack();
}

origin: stackoverflow.com

JLabel l = new JLabel(text, alignment);
l.setBorder(new LineBorder(Color.RED, 2));
return l;
SwingUtilities.invokeLater(new Runnable() {
  public void run() {
    JPanel p = new JPanel(new GridLayout(2,2,4,4));
    p.setBackground(Color.black);
    p.setBorder(new EmptyBorder(4,4,4,4));
    JPanel border = new JPanel(new BorderLayout());
    border.add(getLabel(
      "Border", SwingConstants.CENTER), BorderLayout.CENTER);
    p.add(border);
    JPanel gridbag = new JPanel(new GridBagLayout());
    gridbag.add(getLabel("GridBag"));
    p.add(gridbag);
    p.add(box);
    JFrame f = new JFrame("Streeeetch me..");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(p);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
java.awtBorderLayout

Javadoc

A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER. When adding a component to a container with a border layout, use one of these five constants, for example:

Note: The following code examples include classes that do not appear in this specification. Their inclusion is purely to serve as a demonstration.

 
Panel p = new Panel(); 
p.setLayout(new BorderLayout()); 
p.add(new Button("Okay"), BorderLayout.SOUTH); 
As a convenience, BorderLayout interprets the absence of a string specification the same as the constant CENTER:
 
Panel p2 = new Panel(); 
p2.setLayout(new BorderLayout()); 
p2.add(new TextArea());  // Same as p.add(new TextArea(), BorderLayout.CENTER); 
The components are laid out according to their preferred sizes and the constraints of the container's size. The NORTH and SOUTH components may be stretched horizontally; the EAST and WEST components may be stretched vertically; the CENTER component may stretch both horizontally and vertically to fill any space left over.

Here is an example of five buttons in an applet laid out using the BorderLayout layout manager:

The code for this applet is as follows:


 
import java.awt.*; 
import java.applet.Applet; 
public class buttonDir extends Applet { 
public void init() { 
setLayout(new BorderLayout()); 
add(new Button("North"), BorderLayout.NORTH); 
add(new Button("South"), BorderLayout.SOUTH); 
add(new Button("East"), BorderLayout.EAST); 
add(new Button("West"), BorderLayout.WEST); 
add(new Button("Center"), BorderLayout.CENTER); 
} 
} 

Most used methods

  • <init>
    Constructs a border layout with the specified gaps between components. The horizontal gap is specifi
  • setHgap
    Sets the horizontal gap between components.
  • setVgap
    Sets the vertical gap between components.
  • getLayoutComponent
  • addLayoutComponent
  • layoutContainer
    Lays out the container argument using this border layout. This method actually reshapes the componen
  • getHgap
    Returns the horizontal gap between components.
  • getVgap
    Returns the vertical gap between components.
  • removeLayoutComponent
    Removes the specified component from this border layout. This method is called when a container call
  • getConstraints

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setScale (BigDecimal)
  • startActivity (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • JFileChooser (javax.swing)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now