# TIP: Border Layout can Adapt to Orientation

DevFeed: [TIP: Border Layout can Adapt to Orientation](<https://devfeed.tech/articles/tip-border-layout-can-adapt-to-orientation-19566.md>)

Original publisher: [Read original article](<https://www.codenameone.com/blog/tip-border-layout-can-adapt-orientations/>)

Author: Shai Almog

Published: 2016-10-30T00:00:00Z

Content type: tutorial

Language: en

Sources: [CodeName One](<https://devfeed.tech/sources/codename-one.md>)

Topics: [ui](<https://devfeed.tech/topics/ui.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [automatic](<https://devfeed.tech/tags/automatic.md>), [code](<https://devfeed.tech/tags/code.md>), [component](<https://devfeed.tech/tags/component.md>), [layout](<https://devfeed.tech/tags/layout.md>), [ui](<https://devfeed.tech/tags/ui.md>)

## AI overview

This tutorial explains how to adapt a BorderLayout interface to portrait and landscape orientations. It demonstrates swapping the north component to another border position when landscape mode has more usable space, using the defineLandscapeSwap method.

## Source excerpt

Some designs don't work well in landscape/portrait mode and we need to adapt them to fit the orientation of the device e.g. when we have a large graphic element (icon etc.) on top/below and we no longer have room for that element. As an example check out the code below: Form hi = new Form("Swap", new BorderLayout()); hi.add(BorderLayout.NORTH, FlowLayout.encloseCenter( new Label(duke.scaledWidth(Display.getInstance().convertToPixels(40))))); hi.add(BorderLayout.CENTER, ComponentGroup.enclose( new TextField("", "Username"), new TextField("", "Password", 20, TextField.PASSWORD) )); hi.show(); It produces this image in portrait which matches our expectations: