1 Replies - 1607 Views - Last Post: 18 January 2011 - 08:08 PM Rate Topic: -----

#1 Tenpa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-November 10

Tabbed pane help..need to add buttons, and stuff >_>

Posted 18 January 2011 - 07:46 PM

Based on the tabbed pane tutorial on java website, I create this;

public class adminPanel extends JPanel {
  
  public adminPanel() {
    super(new GridLayout(0,1,5,5));
    
    //Tabbed Pane
    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon icon = createImageIcon("images/Main.gif");
    ImageIcon iconS = createImageIcon("images/Search.gif");
    ImageIcon iconA = createImageIcon("images/Add.gif");
    ImageIcon iconD = createImageIcon("images/Delete.gif");
    ImageIcon iconM = createImageIcon("images/Modify.gif");
    
    JPanel panel1 = createInner("Welcome, Administrator");
                                   
    
    tabbedPane.addTab("Main", icon, panel1, "Main tab");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
    
    
    JPanel panel2 = createInner("Panel #2");
    tabbedPane.addTab("Search", iconS, panel2,
                      "Search by employee name");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
    
    JPanel panel3 = createInner("Panel #3");
    tabbedPane.addTab("Add", iconA, panel3,
                      "Add new Employee account");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
    
    JPanel panel4 = createInner("Panel #4");
    tabbedPane.addTab("Delete", iconD, panel4,
                      "Delete Employee account");
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
    
    
    JPanel panel5 = createInner("ASDFG");
    panel4.setPreferredSize(new Dimension(410, 50));
    tabbedPane.addTab("Modify", iconM, panel5,
                      "Modify Employee information");
    tabbedPane.setMnemonicAt(4, KeyEvent.VK_5);
    
    add(tabbedPane);
   
 
    
  }
  
  
  /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = adminPanel.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
    protected JPanel createInner(String text) {
        JPanel jplPanel = new JPanel();
        JLabel jlbDisplay = new JLabel(text);
        jlbDisplay.setHorizontalAlignment(JLabel.CENTER);
        jplPanel.setLayout(new GridLayout(1, 1));
        jplPanel.add(jlbDisplay);
        return jplPanel;

  
    }
    
      
}




now my Main GUI is in a DIFFERENT class. And in that class, I added this tabbed pane into a frame. So when I click a button, it access adminPanel and brings it up. I want to include buttons from my main GUI class in my panels, but how? I am weak on syntax :[

Is This A Good Question/Topic? 0
  • +

Replies To: Tabbed pane help..need to add buttons, and stuff >_>

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Tabbed pane help..need to add buttons, and stuff >_>

Posted 18 January 2011 - 08:08 PM

your createInner() method is quite a simple method that can be used as a proof of concept but won't be used in real life.
It creates a JPanel with GridLayout(1,1) which means that can only contain one component which is the JLabel you add to it.

In real life, all your tabs won't show the same thing, or may be will but unless all your tabs contain excactly the same JPanel with the same number of JLabel and JButtons (may be with different text on them) you will have to create
createInnerOne();
createInnerTwo();
createInnerThree();
that will construct your different JPanel to be put in your different tabs
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1