Search code examples
javaswingjbuttongrid-layoutborder-layout

On Screen Keyboard gui is not working


I am making a trying to display a textarea at the top and Keyboard keys below it, but when I run this code, the whole thing is mixed. What am I doing wrong and how can I solve it? Here is the code:

public Keyboard()
{
    super("Typing Tutor");

    pane1= new JPanel();
    pane2= new JPanel();
    pane3= new JPanel();
    pane4= new JPanel();
    pane5= new JPanel();
    pane6= new JPanel();

    glayout= new GridLayout(5,14);
    text= new JTextArea(770,300);

    text.setFocusable(true);

    Handler = new HandlerClass();

    pane1.add(text);

    setLayout(glayout);

    but= new JButton[57];

    AssignLettersToButtons();

    text.addKeyListener(Handler);

    add(pane1,BorderLayout.NORTH);
    add(pane2);
    add(pane3);
    add(pane4);
    add(pane5);
    add(pane6);

}

private void AssignLettersToButtons()
{       
    for(int i=0;i<names.length;i++)
    {
        if(i<14)
        {
            but[i]=new JButton(names[i]);
            pane1.add(but[i]);
        }
  }

enter image description here


Solution

  • Design it may take at least 3 panels. As in followingenter image description here