| | |
Java GUI problem... contents of JFrame is invisible...
![]() |
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.
Any help would be much appreciated.
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.
Java Syntax (Toggle Plain Text)
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.
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
There was a few problems. I've got a working version below that you can look at. If you have an older version of java it may not run correctly. Now, you'll have to extend JFrame to get some of the methods I'm using, which I prefer to extend JFrame anyways.
Java Syntax (Toggle Plain Text)
import java.awt.*; import javax.swing.*; public class test extends JFrame{ JTabbedPane JTP; JPanel panel1, panel2; JSlider JS; public test(){ 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); Container content = getContentPane(); content.add(JTP); setContentPane(content); setTitle("Test"); setSize(400,400); setVisible(true); } public static void main(String[] args){ test T = new test(); } }
![]() |
Similar Threads
- Java / GUI Developer Needed (UK) (Software Development Job Offers)
- java gui libraries (Java)
- basic java GUI problem (Java)
- two Java GUI problems - please help (Java)
Other Threads in the Java Forum
- Previous Thread: netbeans 4.0 HELP!
- Next Thread: classpath
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






