Hi all...
I have a JFrame, which contains a JTabbed Pane, which contains two JPanels.
The problem is that when I run the program, a completely grey frame shows up, and the contents only becomes visible when I click on the border of the frame.
Here is the code. Compile & run to see what I mean. I already tried repainting the contents of the frame in the main program, didn't work.
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTabbedPane;
public class test{
JFrame mainFrame;
JTabbedPane JTP;
JPanel panel1, panel2;
JSlider JS;
public test(){
mainFrame = new JFrame();
panel1 = new JPanel();
panel1.setBackground(Color.black);
panel1.setForeground(Color.white);
JS = new JSlider();
JS.setForeground(Color.white);
JS.setMinimum(0);
JS.setMaximum(100);
JS.setMinorTickSpacing(5);
JS.setMajorTickSpacing(10);
JS.setPaintTicks(true);
JS.setPaintLabels(true);
panel2 = new JPanel();
panel2.setBackground(Color.black);
panel2.setForeground(Color.white);
panel2.setLayout(new BorderLayout());
panel2.add(JS, BorderLayout.CENTER);
JTP = new JTabbedPane();
JTP.add("Tab1", panel1);
JTP.add("Tab2", panel2);
JTP.setForeground(Color.green);
mainFrame.getContentPane().add(JTP);
mainFrame.setVisible(true);
mainFrame.setTitle("Test");
mainFrame.setSize(400,400);
}
public static void main(String[] args){
test T = new test();
T.mainFrame.repaint();
T.panel1.repaint();
}
}
Any help would be much appreciated. :)