Question: i am creating a jlist using swing and i want to create that list from top most right corner to top most left corner how can i do that

i did following code

```
package demoipis;

import java.awt.Toolkit;
import javax.swing.*;

public class CreateList{
  public static void main(String[] args) {
  String subject[] = {"Math   English"};
  JFrame frame = new JFrame("Creating a JList Component");
  JPanel panel = new JPanel();
  Toolkit tk = Toolkit.getDefaultToolkit(); 
  int xSize = ((int) tk.getScreenSize().getWidth());  
int ySize = ((int) tk.getScreenSize().getHeight()); 
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  JList list = new JList(subject);
  frame.setUndecorated(true);
  frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
  panel.add(list);
  frame.add(panel);
  frame.setSize(xSize,ySize);  
//frame.show();  

  frame.setVisible(true);
  }
}

```

how can i achieve desired output?

Thanks in advance

Answer: 
The default layout of a JFrame is a BorderLayout. So add your JList to a JScrollPane and add the scrollpane to the NORTH of the BorderLayout.

```
JList list = new JLIst(...);
JScrollPane scrollPane = new JScrollPane(list);
frame.add(scrollPane, BorederLayout.NORTH);

```

now the list will take all the horizontal space of the frame.
Try This Demo example :

```
    import java.awt.*;
    import java.awt.Toolkit;
    import javax.swing.*;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.FlowLayout;

    class CreateList{
 public static void main(String[] args) {
 String subject[] = {"Math", " English", "  Hindhi", "   java", "  c ", " c++ "," cobol ","          python          ruby and rail                c#            .net         asp.net                           Haskell "};
JFrame frame = new JFrame("Creating a JList Component");
JPanel panel = new JPanel(new BorderLayout());
panel.setLayout(new BorderLayout());
Toolkit tk = Toolkit.getDefaultToolkit(); 
int xSize = ((int) tk.getScreenSize().getWidth());  
int ySize = ((int) tk.getScreenSize().getHeight()); 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JList list = new JList(subject);
JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
frame.setUndecorated(true);
panel.add(scrollPane, BorderLayout.NORTH);
frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

frame.add(panel);
frame.setSize(xSize,ySize);  
frame.show();  

frame.setVisible(true);
}
}

```

![enter image description here](https://i.stack.imgur.com/DRbs1.png)