Swing ; Panels
Hello,
A friend has designed a graphic interface
with a tabbedpane
I want to insert a button in one of the tabs
JButton hej =new JButton("Min hejknapp") ;
JLabel hejsan =new JLabel() ;
hejsan.add(hej) ;
calendarPanel.add(hejsan) ;
But it's not visible
Can you see why? :)
Kind regards// jR
btw here's the rest of the code
/**
InfoGraphics.java
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.event.*;
publicclass InfoGraphics
extends JFrame
implements ActionListener
{
//Number of days in each month
int JAN_DAYS = 31,
FEB_DAYS = 28,
MAR_DAYS = 31,
APR_DAYS = 30,
MAY_DAYS = 31,
JUN_DAYS = 30,
JUL_DAYS = 31,
AUG_DAYS = 31,
SEP_DAYS = 30,
OCT_DAYS = 31,
NOV_DAYS = 30,
DEC_DAYS = 31;
//First day of each month in 2006
// 0 = monday, 6 = sunday
int JAN_FIRST = 6,
FEB_FIRST = 2,
MAR_FIRST = 2,
APR_FIRST = 5,
MAY_FIRST = 0,
JUN_FIRST = 3,
JUL_FIRST = 5,
AUG_FIRST = 1,
SEP_FIRST = 4,
OCT_FIRST = 6,
NOV_FIRST = 2,
DEC_FIRST = 4;
//Ett g鋘g paneler
JPanel backGroundPanel,
calendarPanel;
JPanel coursePanel ;
JPanel labPanel ;
JPanel boxPanel;
JPanel dayActivity ;
//En tabbedPane
JTabbedPane tabbedPanel;
//En JComboBox f鰎 att v鋖ja m錸ad
JComboBox monthBox;
//En vector f鰎 m錸aderna
Vector <Month> monthVector;
public InfoGraphics()
{
super("InfoSys");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//En bakgrund
backGroundPanel =new JPanel(new BorderLayout());
//Skapa m錸aderna och lagra dem i m錸adsvectorn
monthVector =new Vector<Month>();
monthVector.add(new Month("January 2006", JAN_FIRST, JAN_DAYS));
monthVector.add(new Month("February 2006", FEB_FIRST, FEB_DAYS));
monthVector.add(new Month("March 2006", MAR_FIRST, MAR_DAYS));
monthVector.add(new Month("April 2006", APR_FIRST, APR_DAYS));
monthVector.add(new Month("May 2006", MAY_FIRST, MAY_DAYS));
monthVector.add(new Month("June 2006", JUN_FIRST, JUN_DAYS));
monthVector.add(new Month("July 2006", JUL_FIRST, JUL_DAYS));
monthVector.add(new Month("August 2006", AUG_FIRST, AUG_DAYS));
monthVector.add(new Month("September 2006", SEP_FIRST, SEP_DAYS));
monthVector.add(new Month("October 2006", OCT_FIRST, OCT_DAYS));
monthVector.add(new Month("November 2006", NOV_FIRST, NOV_DAYS));
monthVector.add(new Month("December 2006", DEC_FIRST, DEC_DAYS));
//M錸adsnamn f鰎 att stoppa in i en combobox
String[] monthNames ={"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"};
//Paneler som visas i tabbarna. Dessa ska ers鋞tas med
//paneler som skapas av m錸ad, kurser och laborationer...
//Eller s?beh錶ler vi dessa paneler och l鋑ger in inneh錶lspaneler
//som i sin tur skapas av m錸ad/kurs/lab...
calendarPanel =new JPanel(new BorderLayout());
dayActivity =new JPanel(new BorderLayout());
coursePanel =new JPanel();
JLabel courseText =new JLabel("Ers鋞t mig med en riktig kurslista");
coursePanel.add(courseText);
labPanel =new JPanel();
JLabel labText =new JLabel("Ers鋞t mig med en riktigt lablista");
labPanel.add(labText);
JButton hej =new JButton("Min hejknapp") ;
JLabel hejsan =new JLabel() ;
hejsan.add(hej) ;
calendarPanel.add(hejsan) ;
//Tabbar
tabbedPanel =new JTabbedPane();
tabbedPanel.addTab("Kalender", calendarPanel);
tabbedPanel.addTab("Kurser", coursePanel);
tabbedPanel.addTab("Laborationer", labPanel);
tabbedPanel.setMnemonicAt(0, KeyEvent.VK_K);
tabbedPanel.setMnemonicAt(1, KeyEvent.VK_U);
tabbedPanel.setMnemonicAt(2, KeyEvent.VK_L);
//Fixa en comboBox
monthBox =new JComboBox(monthNames);
monthBox.addActionListener(this);
monthBox.setActionCommand("chooseMonth");
boxPanel =new JPanel();
boxPanel.add(monthBox);
calendarPanel.add(boxPanel, BorderLayout.SOUTH);
//dayActivity.add(boxPanel, BorderLayout.SOUTH) ;
System.out.println("Hej Inuti InfoGraphics konstruktor") ;
//dayActivity.add((monthVector.get(0)).getCalendar());
//L鋑g till en kalender
calendarPanel.add((monthVector.get(0)).getCalendar());
//calendarPanel.add(new JLabel(new ImageIcon("white_horse.gif"))) ;
//L鋑g till saker i bakgrundspanelen
backGroundPanel.add(tabbedPanel);
//We start by showing the loginPanel
setContentPane(backGroundPanel);
//S鋞t storleken och visa den
setSize(800, 600);
setResizable(false);
setVisible(true);
}//End InfoGraphics
publicvoid actionPerformed(ActionEvent e)
{
//Testutskrift
System.out.println("Nu h鋘de det visst n錿t...");
if ("chooseMonth".equals(e.getActionCommand()))
{
//Vilken m錸ad valdes?
int i = monthBox.getSelectedIndex();
//Ta bort den gamla kalendern och l鋑g till den nya
calendarPanel.remove(1);
calendarPanel.add((monthVector.get(i)).getCalendar());
}//End if chooseMonth
}//End actionPerformed
//test DayActivity
privatevoid testDA(){
dayActivity =new JPanel() ;
}
}//End class

