Results 1 to 5 of 5
- 04-26-2012, 05:37 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 41
- Rep Power
- 0
What am I doing wrong here? please help
I am trying to call my TabPanels Class and display a button in one of the Tabs. I am able to display all the tabs but I can not see the button. what am I doing wrong here? please help.
Java Code:// TabPanels Class package test.gui; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; public class TabPanels extends JFrame{ JFrame myFrame = null; // main to run and test this part of the program /* public static void main(String [] args) { new TabPanels(); } */ public TabPanels() { JTabbedPane tp = new JTabbedPane(); add(tp); tp.addTab("Tab1",new JPanel()); tp.addTab("Tab2", new JPanel()); tp.addTab("Tab3", new JPanel()); setPreferredSize(new Dimension(1360,768)); // myFrame.setPreferredSize(new Dimension(1360,768)); pack(); setVisible(true); } } // layerOne class package test.gui; import javax.swing.*; public class layerOne extends JPanel { public static void main(String [] args) { new layerOne(); } private JButton btn1; private JButton btn2; private JButton btn3; private JButton btn4; private JPanel myPanel; TabPanels tabs; public layerOne() { initComponents(); } private void initComponents() { tabs = new TabPanels (); // create new tab panels; btn1 = new JButton(); myPanel = new JPanel (); btn1.setText("Test"); GroupLayout layout = new GroupLayout(myPanel); myPanel.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(236, Short.MAX_VALUE) .addComponent(btn1) .addGap(234, 234, 234)) ); layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(137, 137, 137) .addComponent(btn1) .addContainerGap(214, Short.MAX_VALUE)) ); tabs.add(myPanel); } }Last edited by atrodeyo; 04-26-2012 at 05:40 PM.
- 04-26-2012, 06:03 PM #2
Re: What am I doing wrong here? please help
Is that generated code? Try getting rid of that and writing the GUI layout yourself.
If you don't understand my response, don't ignore it, ask a question.
- 04-26-2012, 06:07 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 59
- Rep Power
- 0
Re: What am I doing wrong here? please help
You are creating tabs, adding newly created JPanels to them which do don't have a variable to access them through, i.e. JPanel myPanel = new JPanel(); then you have a seperate class that extends JPanel() which is never used. Did you mean to do
Java Code:tp.addTab("Tab1",new layerOne()); tp.addTab("Tab2", new layerOne()); tp.addTab("Tab3", new layerOne());Last edited by k1ng; 04-26-2012 at 06:08 PM. Reason: fixed some uglyness
- 04-26-2012, 09:48 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 41
- Rep Power
- 0
Re: What am I doing wrong here? please help
thanks it worked.
- 04-26-2012, 10:30 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 59
- Rep Power
- 0
Similar Threads
-
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 4Last Post: 06-11-2013, 01:37 AM -
What am I doing wrong?
By javajen in forum New To JavaReplies: 3Last Post: 04-11-2011, 05:35 PM -
What did I do wrong?
By GoingThroAPhase in forum New To JavaReplies: 4Last Post: 04-03-2010, 04:51 AM -
what's wrong here ?
By doha786 in forum New To JavaReplies: 6Last Post: 03-26-2010, 12:21 PM -
Please help, what am I doing wrong?
By mmac1218 in forum New To JavaReplies: 2Last Post: 09-01-2009, 11:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks