-1

When I run the code , none of the components, neither the JTable or the buttons will show up inside the tab, they appear on the side of the tab window instead. any reason why that is ?

public void GUIcode() {


    setLayout(new GridBagLayout());

    setBounds(100, 100, 450, 300);

    panel = new JPanel();
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));
    setContentPane(panel);
    panel.setLayout(null);

    JTabbedPane tabb = new JTabbedPane(JTabbedPane.TOP);
    tabb.setBounds(0, 0, 400, 300);
    panel.add(tabb);

    JPanel panel = new JPanel();
    tabb.addTab("vis vare", null, panel, null);
    panel.setLayout(null);

    tabellinnhold = new DefaultTableModel(defaulttabell,kolonnenavn);
    bytabell = new JTable(tabellinnhold);
    rullefelt = new JScrollPane(bytabell);

    panel.add(rullefelt);
    add(panel);

    koble = new JButton("koble til");
    lukke = new JButton("lukke");
    hente = new JButton("Hente data");
    avslutt = new JButton("Avslutt");
    // legger til knappepanel
    panel.setLayout(new GridLayout(1,4));
    panel.add(koble);
    panel.add(lukke);
    panel.add(hente);
    panel.add(avslutt);

    //action drit
    koble.addActionListener(this);
    lukke.addActionListener(this);
    hente.addActionListener(this);
    avslutt.addActionListener(this);

}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

2

Because you added the JTabbedPane to panel and then you wrote

JPanel panel = new JPanel();

and added other components, incl. the JScrollPane and buttons to it. First, the code cannot compile this way. Second, please, change the addition order and add scroll pane to tabs

igorepst
  • 1,230
  • 1
  • 12
  • 20
  • If the answer helped you, please, accept it by using a checkbox, so other users will find the answer easier, if needed – igorepst Apr 11 '19 at 17:06