I am making a GUI of Stack using Java. Here is my code
private void StackActionPerformed(java.awt.event.ActionEvent evt)
{
b1=new JButton("Push");
b2=new JButton("Pop");
b3=new JButton("Peek");
b4=new JButton("Clear");
b1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pushButtonActionPerformed(evt);
}
});
tb.add(b1);
tb.add(b2);
tb.add(b3);
tb.add(b4);
frame_st.add(tb);
frame_st.setExtendedState(Frame.MAXIMIZED_BOTH);
}
Here I am adding buttons to my toolBar (tb) everything is working fine . I am not getting any error. But after compiling am not getting the desired result . toolBar(tb) is not able to add the buttons (b1,b2,etc)
If you’re adding components after a GUI has been rendered, don’t forget to revalidate and repaint containers after you’ve changed the components they hold.
Also key here are what layout managers are your tb JPanel and JFrame contentPane using?