Changing JPanels in a JSplitPane

Hi
I'm busy writing a swing application that consists of a JTabbedPane with each tab being a JSplitPane. Each of these JSplitPanes has a bunch of buttons on the left hand side, and pressing a button brings up a JPanel on the right hand side with the appropriate form on it. The problem is that i can bring up one panel, but the minute i click another button to bring up a different panel the application just hangs... I have no idea why.
The code i'm using to change panels looks something like this.
private void generalConfigPressed(java.awt.event.ActionEvent evt) {
generalConfigPanel tmp = new generalConfigPanel();
tmp.setCommunicator(comm);
jSplitPane1.remove(jSplitPane1.getRightComponent());
jSplitPane1.setRightComponent(tmp);
generalConfigPanel is a JPanel. setCommunicator is a method i need to invoke before displaying the panel.
I'm using j2sdk 1.4.2
Any suggestions would be most appreciated.
Thanks in advance
Sebastian

You might try making the right pane a cardstack instead of removing and adding components with each mouse click

Similar Messages

  • Using ActionListener to change JPanels

    Hey,
    I'm currently writing an app which uses a set of JToggleButtons to alter the selection of a range of user interface elements on different panels. When a user selects a particular toggle button i want the panel or frame to change to a different panel or frame. Ive got all the action listeners setup and all the components added to different JPanel's at the moment.
    I just wondered if anyone knew a good way to switch between these panels before i have a go and probably do it wrong.
    Hopefully someone will be able to help!
    Thanks for any help
    Damo.

    thanks for all the replies everyone.
    i did think of using a tabbed pane to do it, but i dont really want the tabs at the top as the selected pane is dependent on a range of toggle buttons, not the actual tab selectors.
    Ill look into both of the ideas.
    Thanks again
    Damo.

  • Change JPanel Components

    Hi ya,
    I need some help with what seems like quite a simple problem ... on an action from lets say a JButton I need the contents of a JPanel to change.
    I thought this would work :
    this.getContectPane().add(newPanel);where the current object holds the main JPanel which I want to change. This does not seem to work even if I add the pack(); or setVisible();
    How do I set this view to a new JPanel Object??
    Thanks

    Well normally all you need to do is:
    validate() (for AWT components or revalidate() for
    Swing components
    repaint() is sometimes required.
    If you need further help then you need to create a
    [url
    http://homepage1.nifty.com/algafield/sscce.html]Short,
    Self Contained, Compilable and Executable, Example
    Program that demonstrates the incorrectbehaviour, because I can't guess exactly what you are
    doing based on the information provided.
    And don't forget to use the [url
    http://forum.java.sun.com/help.jspa?sec=formatting]Cod
    e Formatting Tags so the code retains its
    original formatting.
    Thanks for everyones help but I have resolved the problem here, simple little error.

  • Changing JPanel with button click.

    Hi, I have a class call TOC(Table of Content) which contains all the buttons. One class call MainController. All buttons I add an actionListener which the MainController class will handle. Anothe class which is the main one which contain a JPanel.
    When I click on the button in TOC class, it will go through the MainController class and display the respective JPanel associate with the button.
    Now the problem is how do I change the JPanel in the main class with a click on the button in TOC class?
    Please advise. Thanks in advance.

    Not sure what you mean exactly. However,
    Assuming that your view class is a JPanel, when you create your controller,
    ViewPanel view = new ViewPanel();
    MainController controller = new MainController(viewPanel);
    In MainController track a reference to your viewPanel. Also in viewPanel have a method called setCurrentPanel(JPanel panel). then int he controller's action listener
    public void actionPerformed(ActionEvent ev) {
    JPanel pnl = (JPanel) panelMap.get(ev.getSource().getName());
    viewPanel.setCurrentPanel(pnl);
    I am assuming you have a way of mapping each button to the panel it will use, which is what is in the panelMap. The viewPanel can have a CardPanel layout for the panels it displays and its setCurrentPanel, can bring to front/oradd the specified panel.
    Good luck, hope this helps :-)

  • Changing JPanels at runtime

    Hi guys,
    I'm writing a turorial apllication. I want to break down the information into JPanels, however I can't seem to swap between JPanels at runtime. I've tried calling validate and revalidate and then repaint... but I cant seem to get it working.
    This is probably a really common question but I couldn't find anything in the archives. Any help would be greatly appreciated.
    Cheers
    Stuart

    I'm assuming you're removing the old one before adding the new, in which case there isn't normally a problem so we'd have to see some code. Something I find works quite well for this is the CardLayout - check the docs. It lets you add a load of panels on top of one another and refer to each with a string. You then just call CardLayout.show("name") and this component comes to the top.
    hth

  • Extending JPanel changes JPanel behavior

    All,
    I am trying to center a JPanel in the middle of my JFrame. Below is the code I use to center the JPanel. What is confusing me is that when the panel in question, actionPnl, is declared as a JPanel, the centering code works beautifully. When I declare it as a CanvasPanel (see code below) it does not show up at all. Now, I thought that when you use �Extends� that the class you are creating inherits all attributes of the class you are extending however this behavior suggests otherwise. Am I overlooking some fundamental ingredient?
    //private CanvasPanel actionPnl = new CanvasPanel();
    private JPanel actionPnl = new JPanel();
    private Box xp = Box.createHorizontalBox();
    private Box yp = Box.createVerticalBox();
    private void center()
      xp.add(Box.createHorizontalGlue());
      xp.add(actionPnl);
      xp.add(Box.createHorizontalGlue());
      yp.add(Box.createVerticalGlue());
      yp.add(xp);
      yp.add(Box.createVerticalGlue());
    }//end center()
    public class CanvasPanel extends JPanel
      private Image image;
    public CanvasPanel()
       setBackground (Color.WHITE);
       setPreferredSize(new Dimension(600, 100));
    }//end constructor CanvasPanel()
    public void paintComponent(Graphics g)
       g.drawImage(image, 0, 0, null);
       g.dispose();
    public void setImage(Image inImage)
       image = inImage;
    }

    We never want to see you entire program. We only want
    to see the code that demonstrates the incorrect
    behaviourI pieced this together and it has the same behavior. It is what I would call "hack code" and does not follow good practices. But it gets the point across. Just toggle which actionPnl declaration to comment out to see the difference.
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.image.BufferedImage;
    import java.awt.Graphics;
    public class test extends JFrame
    Container c;
    boolean btnControl = false;
    /******** toggle these two *********/
    //private CanvasPanel actionPnl = new CanvasPanel();
    private JPanel actionPnl = new JPanel();
    private Box xp = Box.createHorizontalBox();
    private Box yp = Box.createVerticalBox();
    public test()
    //container
    c = getContentPane();
    c.setBackground(Color.BLACK);
    c.setLayout(new BorderLayout());
    //construction
    buildActionPnl();
    //add to JFrame
    c.add(yp, BorderLayout.CENTER);
    setSize(1200, 950);
    setVisible(true);     
    }//end constructor balance()
    private void buildActionPnl()
      center();
    }//end buildActionPnl()
    private void center()
      xp.add(Box.createHorizontalGlue());
      xp.add(actionPnl);
      xp.add(Box.createHorizontalGlue());
      yp.add(Box.createVerticalGlue());
      yp.add(xp);
      yp.add(Box.createVerticalGlue());
    }//end center()
    public static void main(String args[])
      test t = new test();
    t.addWindowListener(
                new WindowAdapter(){
                     public void windowClosing(WindowEvent we){
                          System.exit(0);
    public class CanvasPanel extends JPanel
      private Image image;
    public CanvasPanel()
       setBackground (Color.WHITE);
       setPreferredSize(new Dimension(600, 100));
    }//end constructor CanvasPanel()
    public void paintComponent(Graphics g)
       g.drawImage(image, 0, 0, null);
       g.dispose();
    }I will research your suggested LayoutManager information and get back with how it works for me. At the moment I do not have code to control where each image is painted, that is what I am trying to take on.
    Thanks for the help, it is appreciated!

  • Problem with changing background colors in JPanels

    Hi,
    I have made an applet with Grid Layout and I have added JPanels in each grid. I have assigned a background color to all panels.
    Now what i am trying to do is, change the clicked JPanel's background color to "blue" on a mouse click and convert the previous changed JPanel's background to originally assigned color.
    This is the code that I have used:
    JPanel temp=null, m;
    String tempc, m_color;
    public void mouseClicked(MouseEvent me)
              m=(JPanel)me.getComponent();
              if(m!=temp)
              m_color=m.getBackground().toString();   // retaining current background color so as to change later
              m.setBackground(Color.blue);
                   if(temp!=null) 
                        temp.setBackground(Color.getColor(tempc));  // change back to original color
              tempc=m_color;       //tempc and m_color are Strings
              temp=m;               //temp and m are JPanels
         }When I am executing the above logic, background color changes to blue on a mouse click but the previously changed JPanel is not changing back to original color.
    Can anyone please tell where is the above logic going wrong??
    Thanks
    Rohan

    Hi Camickr,
    I tried to do it without changing Color to Strings but i was getting an error in the line temp.setBackground(Color.tempc);, so i decided to change it to String and retrieve it's value in the method.
    SSCCE for my code is:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.lang.reflect.InvocationTargetException;
    <applet code="test" width=400 height=400>
    </applet>
    public class test extends JApplet
         JPanel t[][]=new JPanel[8][8];
         JPanel p[][];
         public void init()
         try{
         SwingUtilities.invokeAndWait(new Runnable()
              public void run()
                   t=makeGUI(8,8);
                   logic(t,8,8);
         }catch(InterruptedException e){e.printStackTrace();}
         catch(InvocationTargetException e){e.printStackTrace();}
    /* Board*/
    private JPanel[][] makeGUI(int rows, int cols)
        p = new JPanel[rows][cols];
        Container contentPane = getContentPane();
        contentPane.setLayout(new GridLayout(rows, cols));
        for (int i = 0; i < rows; i++)
          for (int j = 0; j < cols; j++)
            p[i][j] = new JPanel();
            contentPane.add(p[i][j]);
            if (i % 2 == j % 2)
              p[i][j].setBackground(Color.white);
              else
              p[i][j].setBackground(Color.darkGray);
         return p;
    private void logic(JPanel p[][], int rows, int cols)     
              for (int i = 0; i < rows; i++)
              for (int j = 0; j < cols; j++)
              final int k=i, l=j;
              p[i][j].addMouseListener(new MouseListener()
                   JPanel temp=null,m;
                   String tempc, m_color;
                   public void mouseClicked(MouseEvent me)
                        m=(JPanel)me.getComponent();
                        if(m!=temp)
                        m_color=m.getBackground().toString();     //retaining current background color
                        m.setBackground(Color.blue);
                        if(temp!=null)     // this method sets the panel
                             {               //     to its original color
                             temp.setBackground(Color.getColor(tempc));
                        tempc=m_color;     //color Strings
                        temp=m;          //JPanels
                   public void mouseEntered(MouseEvent me){}
                   public void mouseExited(MouseEvent me){}
                   public void mousePressed(MouseEvent me){}
                   public void mouseReleased(MouseEvent me){}
    }

  • JPanel change

    In my program a certain JPanel changes as the user changes between JDialogs.
    To remove the panel, I am calling remove() within the JPanel containing it, giving a reference to the JPanel that is being removed. This seems to work fine.
    Then, to add the new JPanel, I call add() and pass in a reference to the new JPanel and its position (BorderLayout.CENTER).
    The problem is that this new panel does not show until I resize the overall JFrame containing it. This strikes me as a very strange problem. Is there a method I need to call when changing JPanels in this
    manner?
    Thanks,

    Hi nusnus,
    Pleaseo add below two lines to your code after you add new JPanel to it.
    code:
    ========
    fs.invalidate();
    fs.validate();
    fs is the container .
    I hope this will help you out.
    Regards,
    Tirumalarao
    Developer Technical Support,
    Sun Microsystems,
    http://www.sun.com/developers/support.

  • Hw to split the jpanel to 3 jpanels

    Hello frnds,
    In the below mentioned code I need to split the teller panel to three teller can you give any suggestions.
    thank you
    suraw
    package guis.views;
    import guis.controllers.GeneralController;
    import java.awt.Dimension;
    import java.awt.GridBagLayout;
    import java.awt.GridLayout;
    import java.beans.PropertyChangeEvent;
    import java.util.LinkedList;
    import javax.swing.DefaultListModel;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JSplitPane;
    * This is a custom view panel that displays a "document" consisting of a single
    * text element. Both the document and the text element respond to changes in
    * the model state.
    * @author Robert Eckstein
    public class TellerPanelView extends View
         private JPanel tellerPanel,tellerSubPanel;
         private JList teller;
         private JLabel tellerInfo;
         private JSplitPane SplitPane;
         private LinkedList<String> customerAtTeller;
         private JScrollPane listScroller;
         private DefaultListModel tellerlist;
         // The controller used by this view
         private GeneralController controller;
         * Creates new form TextElementDisplayPanel
         * @param controller An object implenting the controller interface that
         * this view can use to process GUI actions
         public TellerPanelView(GeneralController controller) {
              this.controller = controller;
              initComponents();
              localInitialization();
         * Initialization method called from the constructor
         public void localInitialization() {
         /** This method is called from within the constructor to
         * initialize the form.
         private void initComponents() {
              tellerPanel = new JPanel(new GridLayout(2,1));          
         tellerInfo = new JLabel("Teller1: Teller2: Teller3:");
              teller = new JList();
              tellerlist = new DefaultListModel();
              teller.setModel(tellerlist);
              SplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);          
              for (int a = 0; a <= 2; a++)
              listScroller = new JScrollPane(teller,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              customerAtTeller = new LinkedList<String>();
              tellerPanel.add(tellerInfo);
              tellerPanel.add(listScroller);
         public JPanel getTellerPanel() {
              return tellerPanel;
         * Called by the controller when it needs to pass along a property change
         * from a model.
         * @param evt The property change event
         public void modelPropertyChange(PropertyChangeEvent evt) {
              if (evt.getPropertyName().equals(GeneralController.ADD_TRANSACTION)) {
                   String cust = (String) evt.getNewValue();
                   customerAtTeller.addLast(cust);
                   tellerlist.addElement(cust);
              revalidate();
              repaint();
    }

    While it looks like you've split a panel, you really haven't. You've added spcific components to a JPanel that make it look like it's split.
    Ingredients needed: a total of 4 JPanels, and 2 JSplitPanes
    Step 1: Create 2 new JPanels, and then Create a JSplitPane that houses these two JPanels
    JSplitPane jsp1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jPanel2, jPanel3);
    Step 2: Create a 3rd JPanel, and then Create a second JSplit Pane that holds the 3rd JPanel, the JSplitPane created in step 1
    JSplitPane jsp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jPanel1, jsp1);
    Step 3: Now, add the JSplitPane created in step 2 to your original JPanel
    jsp0.add(jsp2); // modify the add according to the screen manager you're using
    You'll want to set properties on EACH of the JSplitPanes:
    ((JSplitPane) jsp1).setDividerSize(6);
    ((JSplitPane) jsp1).setContinuousLayout(true);
    ((JSplitPane) jsp1).setResizeWeight( (iSliderPos * 0.01) ); // VERY IMPORTANT!!!
    ((JSplitPane) jsp1).setDividerLocation( (iSliderPos * 0.01) );
    where int iSliderPos is 0 - 100
    Gotchas: I may look like there is nothing there (empty screen) because there are no components in jsp1, jsp2, and jsp3.
    You'll either need to put components on these JPanels, or force the JPanels to have some size by setting:
    jpanel1.setMinimumSize(new Dimension(80, 60));
    jpanel1.setPreferredSize(new Dimension(800, 600));
    jpanel1.setMaximumSize(new Dimension(1600, 1200));
    jpanel1.setBounds(0,0,800,600);
    jpanel1.setBorder(blackLineBorder);
    (repeat for jpanel2 and jpanel3)
    and the split panes:
    jsp1.setMinimumSize(new Dimension(80, 60));
    jsp1.setPreferredSize(new Dimension(800, 600));
    jsp1.setMaximumSize(new Dimension(1600, 1200));
    jsp1.setBounds(0, 0, 800, 600);
    (repeat for jsp2)
    This was pretty frustrating for me the first couple (of hundred) times. Maybe try to get it working as 2 panels with one split first.
    bcf

  • Changing panels in frame at runtime using NetBeans

    Hi there,
    I'm having trouble changing JPanels in a JFrame at runtime when they were both generated in NetBeans. I find that I can do this easily in a manually coded GUI with the code below. However with NetBeans generated frames and panels it doesn't seem to work.
    So all I really would like to learn is how to change JPanels in a JFrame at runtime when both are generated by NetBeans (New>JFrame Form... and New>JPanel Form...) Any help would be much appreciated.
            // reset panel
            pMain.removeAll();    // main panel added to nb generated frame
            pMain.validate();     // call layout manager
            testPanel = new TestPanel();  // this class extends JPanel (generated)
            pMain.add(testPanel);     // add new panel
            pMain.setVisible(true);     // update panel
            pMain.revalidate();
            pMain.repaint();

    Changing the layout to BorderLayout and adding the new panel to BorderLayout.CENTER with your code sample above doesn't seem to work though.This works for me.
    I created a frame form and a panel form then set the frame layout to border layout and added a remove/add panel at the south.
    frame code looks like this.
    import java.awt.BorderLayout;
    public class MainFrame extends javax.swing.JFrame {
    private boolean isAdded;
    private TestPanel panel; // this is the panel form
    /** Creates new form MainFrame */
    public MainFrame() {
    isAdded = false;
    initComponents();
    // Generated code
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    if(!isAdded) {
    panel = new TestPanel();
    add(panel, BorderLayout.CENTER);
    pack();
    isAdded = true;
    } else {
    remove(panel);
    isAdded = false;
    validate();
    repaint();
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new MainFrame().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    // End of variables declaration
    Somehow I find it very hard to believe that NetBeans is not production ready....The reason we don't use the DnD in nb is that the generated code is not editable and it's hard to maintain.

  • Big problem with JSplitPane

    Hello,
    I feel I'm going mad with Swing.
    I have a main main JTabbedPane: main.
    First component: JEditorPane : source
    Second Component: JPanel : view( = new JPanel())
    In view I have:
    JPanel toolbox to NORTH and JSplitPane: ds to CENTER.
    In ds I have:
    Left component: new JScrollPane(design) where design=new JPanel()
    Right component: JSplitPane(....) : called pe
    First problem:
    In ds the left component is too small. I tried to use all functions available , no result. I want the right component(pe) to have width=200, but no chance. It is too big. Why?
    Second problem:
    The scrolls are not appearing on the left at the ds(JSplitPane)
    Third problem:
    I add different components to design JPanel(the one which is placed into a JScrollPane which is related to the second problem) but nothing happens. They won't appear on design which is the same and without no scrolls.
    Please help me solve this Swing mistery.
    Thank you all.

    The split pane, by default, will size its two halves based on their preferred sizes. If the combined preferred sizes are too small (for the size of the spilt pane) then the extra space is distributed based on JSplitPane's resize weight. The default is to add the extra to the right hand side, see JSplitPane.setResizeWeight for an explanation. If you really want the right hand side to be exactly 200 pixels then you can programmatically move the divider to a location that would leave the right hand side to be 200. Or you can set the preferred size of the component you place there to 200 and set a resize weight that will give the extra space to the left instead of the right.
    I am not sure about why the scroll bars are not showing up. Does it need scroll bars?
    May I suggest creating a simple demo app to show the problem? Often I solve my own problems doing this otherwise you have some code for us to look at and play with.
    Ian

  • How to set Width of a JPanel?

    I am overwirting paintComponent(Graphics g) method to
    draw some g2D in a JPanel.
    I want the drawing processing shown on screen (not flashed out after drawn because it is VERY SLOW).
    So that I CAN NOT use setsize() or setBound() because to change JPanle.width because this is NOT what I wanted(the graphics is shown AFTER is drawn).
    Everytime I call paintComponent(), the width of JPanel is changed.
    My question is : How can change JPanel.width without calling method like setsize() or setBound() .
    Thanks a lot!!

    My code too large, I just show some idea here:
    class caller (){
    myPanel p;
    Graphics2D g2 = (Graphics2D)p.getGraphics();
    //I nee to increase the p.width before call my_paint
    //I CAN NOT use setsize() or setBound()
    //because I want show the drawing process
    //on screen( and that is fast)
    p.my_paint(g2); // how to set p.width ??
    public class myPanel extends JPanel
    public void my_paint(Graphics2D g2)
    //Do my drawing here ,
    // I need to draw thousands of Line2D.
    public void paintComponent(Graphics g){
    Graphics2D g2 = (Graphics2D)g;
    my_paint(g2);

  • Jpanel overlap Forms Component

    Hi all,
    I'm using forms 11g, now i try to add one JPanel (Swing) to DrawPanel (Oracle forms DrawPanel), I add the panel first after that I add other Forms component such as VTextField, VBUtton, after that I change Z-order of JPanel to last index (because i want Jpanel will be overlapped by other forms components) .
    But the result always show the JPanel overlap Form Component.
    For more detail you can view this link : [http://stackoverflow.com/questions/7764532/jpanel-overlap-other-components]
    Thanks in advance
    Best regards,
    Edited by: 891733 on 21:05 16-10-2011

    Hi,
    When i change JPanel to Forms DrawnPanel, i still got this problem,
    And i've already added this post to Java Programming Thread
    jpanel overlap Forms Component

  • Swapping JSplitPane

    public static void setCurrentPane (JSplitPane newPane){
              contentHolder.remove(currentPane);  //contentHolder is a JPanel, currentPane is JSplitPane
              System.out.println ("currentPane removed");
              currentPane = newPane;
              contentHolder.add(currentPane);
              System.out.println ("currentPane added");
         }I have a main class which includes the above method. In the main class, there is also a JFrame which holds everything. Several other classes call the setCurrentPane() method to swap the JSplitPane that is in contentHolder. It works sometimes, and other times, it causes the program to lock up. There is nothing complex in the JSplitPanes, only JButtons and JLabels and I think that I have narrowed it down to this little piece of code. The whole code for the MainClass is directly below and code that example code that calls this class is below that.
    Any help is greatly appreciated.
    package globalVars;
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import javax.swing.UIManager;
    import subject.MathSubject;
    import subject.Science;
    import subject.StarterView;
    public class MainClass {
         private static JSplitPane currentPane;
         private static JSplitPane previousPane;
         private static JSplitPane oldestPane;
         private static JFrame mainWindow;
         private static Container contents;
         private static JLabel title = new JLabel();
         private static JButton subjectNavButton;
         private static java.awt.Dimension navButtonSize = new java.awt.Dimension (125, 20);
         private static JButton catNavButton;
         private static JPanel contentHolder;
         private static JLabel navLabel = new JLabel (new ImageIcon ("files/navImage.png"));
         private static JPanel navButtonHolder;
         private static java.awt.Dimension leftButtonSize = new java.awt.Dimension (180, 40);
         private static java.awt.Dimension rightButtonSize = new java.awt.Dimension (120, 160);
         private static int dividerLocation = 200;
         private static int dividerSize = 1;
         private static JPanel northPanel;
         private static ButtonListener buttonListener = new ButtonListener();
         public static java.awt.Dimension getRightSize(){
              return rightButtonSize;
         public static int getDividerLocations (){
              return dividerLocation;
         public static java.awt.Dimension getLeftSize (){
              return leftButtonSize;
         public static int getDividerSize(){
              return dividerSize;
         public static void setSubjectButton (String s){
              subjectNavButton.setText(s);
         public static void setCatButton (String s){
              catNavButton.setText(s);
         public static void setCurrentPane (JSplitPane newPane){
              oldestPane = previousPane;
              contentHolder.remove(currentPane);
              System.out.println ("currentPane removed");
              previousPane = currentPane;
              currentPane = newPane;
              contentHolder.add(currentPane);
              System.out.println ("currentPane added");
         public static void setTitle (String s){
              title.setText(s);
              title.setFont(title.getFont().deriveFont(18.0f));
         public static void main (String [] args){
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              catch (Exception e){
                   JOptionPane.showMessageDialog(null, "Cannot load system look and feel, using Java default. This may require re-installing JAVA");
              mainWindow = new JFrame();
              contents = mainWindow.getContentPane();
              previousPane = null;
              oldestPane = null;
              currentPane = new StarterView();
              subjectNavButton = new JButton ("Subject Nav Button");
              subjectNavButton.setPreferredSize(MainClass.navButtonSize);
              subjectNavButton.addActionListener(buttonListener);
              catNavButton = new JButton ("Category Nav Button");
              catNavButton.addActionListener(buttonListener);
              catNavButton.setPreferredSize(MainClass.navButtonSize);
              mainWindow.setDefaultCloseOperation( javax.swing.WindowConstants.EXIT_ON_CLOSE );
              contentHolder = new JPanel (new BorderLayout());
              setTitle ("Subjects");
              northPanel = new JPanel (new FlowLayout (FlowLayout.LEFT));
              northPanel.add(subjectNavButton);
              northPanel.add(new JLabel (new ImageIcon ("files/navImage.png")));
              northPanel.add(catNavButton);
              northPanel.add(new JLabel (new ImageIcon ("files/navImage.png")));
              northPanel.add(title);
              contentHolder.add(northPanel, BorderLayout.NORTH);
              contentHolder.add(currentPane, BorderLayout.CENTER);
              contents.add(contentHolder);
              mainWindow.setSize(755, 555);
              mainWindow.setTitle("StepAhead Interactive tools");
              mainWindow.setLocationRelativeTo(null);
              mainWindow.setVisible(true);
         static class ButtonListener implements ActionListener {
              public void actionPerformed (ActionEvent e){
                   if (e.getSource() == catNavButton){
                        System.out.println ("Category HOYO");
                        //replaces the current display with the Category Associated with that Button
                   if (e.getSource() == subjectNavButton){
                        if (subjectNavButton.getText().equals("Math")){
                             System.out.println ("Loading up Math Subject");
                             setCurrentPane (new MathSubject());
                        if (catNavButton.getText().equals("Science")){
                             System.out.println ("Loading up Science Subject");
                             setCurrentPane (new JSplitPane());
                        //replaces the current display with the Subject Associated with that Button
                        System.out.println ("Subject HOYO");
    }CODE THAT CALLS setCurrentPane method
    package categories.math;
    import java.awt.event.*;
    import java.awt.*;
    import globalVars.MainClass;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import button.rightButton;
    import chapters.NumbersChapters.*;
    public class Numbers extends MathCategories implements ActionListener{
         private JPanel rightPane;
         private JButton division;
         private JButton numberPatterns;
         private JButton growthRates;
         private JButton fractions;
         private JButton remainders;
         private JButton counting;
         private JButton probability;
         public Numbers (){
              super();
              rightPane = new JPanel(new FlowLayout (FlowLayout.LEFT));
              numberPatterns = new rightButton ("Number", "Patterns"); //rightButton is a class I created which extends JButton
    //and pre-formats it to conform to a set look
              numberPatterns.addActionListener(this);
              numberPatterns.setPreferredSize(MainClass.getRightSize());
              growthRates = new JButton ("Growth Rates of Sequences");
              growthRates.addActionListener(this);
              growthRates.setPreferredSize(MainClass.getRightSize());
              division = new JButton ("Division");
              division.addActionListener(this);
              division.setPreferredSize(MainClass.getRightSize());
              fractions = new JButton ("Fractions");
              fractions.addActionListener(this);
              fractions.setPreferredSize(MainClass.getRightSize());
              remainders = new JButton ("Remainders");
              remainders.addActionListener(this);
              remainders.setPreferredSize(MainClass.getRightSize());
              counting = new JButton ("Counting");
              counting.addActionListener(this);
              counting.setPreferredSize(MainClass.getRightSize());
              probability= new JButton ("Probability");
              probability.addActionListener(this);
              probability.setPreferredSize(MainClass.getRightSize());
              rightPane.add(numberPatterns);
              rightPane.add(growthRates);
              rightPane.add(division);
              rightPane.add(fractions);
              rightPane.add(remainders);
              rightPane.add(counting);
              rightPane.add(probability);     
              this.setRightComponent(rightPane);
         public void actionPerformed (ActionEvent e){
              super.actionPerformed(e);
              if (e.getSource() == numberPatterns){
                   MainClass.setTitle ("Number Patterns");
                   MainClass.setCurrentPane(new NumberPattern());
              if (e.getSource()== division){
                   MainClass.setTitle ("Division");
                   MainClass.setCurrentPane(new Division());
              if (e.getSource()== growthRates){
                   MainClass.setTitle ("Growth Rates of Sequences");
                   MainClass.setCurrentPane(new GrowthRate());
              if (e.getSource()== fractions){
                   MainClass.setTitle ("Fractions");
                   MainClass.setCurrentPane(new Division());
              if (e.getSource()== remainders){
                   MainClass.setTitle ("Remainders");
                   MainClass.setCurrentPane(new Division());
              if (e.getSource()== counting){
                   MainClass.setTitle ("Counting");
                   MainClass.setCurrentPane(new Division());
              if (e.getSource()== probability){
                   MainClass.setTitle ("Probability");
                   MainClass.setCurrentPane(new Division());
    }

    panel.remove(...);
    panel.add(...);
    panel.revalidate();
    panel.repaint();If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • The visible size of the Let/Right Component for JSplitPane

    Hi all,
    I am doing a project on map plotting. But i Don't know the way to get the visible size of the Let/Right Component (example JPanel) for a JSplitPane. Can anybody help? Thanks a lot!

    Hi,
    if you're just interested in the size you could use getDividerLocation().
    something else could be:
    getJSplitPane().getWidth()-(getJSplitPane().getDividerLocation()+getJSplitPane().getDividerSize())that gives you the Width of the right part
    Phil

Maybe you are looking for

  • Continuous Video Playback from iPod Touch to Apple tv

    hello, I am hoping someone can help me with this issue.  I have searched for hours and am unable to locate a response that has worked for me. I have an iPod Touch (without camera) which plays ALL videos on a playlist consecutivley without returning t

  • Converting date value one day less while transfering from client to server

    Hi, I have very typical problem. My application is in java, we are using oralce 9ias. The problem when the server is running in german locale and client is running in english. We the date value is passed from client to server it is converting to one

  • Newbie question - import jpeg convert to objects

    I have a manuscript in pen and ink.  It uses two cartoon characters and contains bubble text and drawings.  I had the content scanned and converted to a pdf file.  This was then converted to jpeg files, one for each page.  I want to edit these files

  • Media Manager - Album Info

    Folks, I have about 300 CDs ripped as wav files to my PC. The are organized in folders artist/album. I have managed to get Media Monkey (a music manager) and Windows Media Player 11 to recognize album names and display album art even though wav files

  • VERY SLOW PERFORMANCE TRYING TO RUN AN ADF JSPX THAT CONTAINS AN ADF TABLE

    I created a new JDev Application (ADF BC technology), then I created the entities, views, and AppModule using the BC Model wizard, then I enabled JHeadStart on the ViewController project, then I created a new JHS Application Configuration, then I gen