Nested panels in Swing

Hi, everyone
i want to know about nested panels in detail. If we make heirarchy of panels at third level then how we can perform drawing in uppermost(last child). please suggest me ideas and give links that gives sufficient matter about it.
Thanks in advance.
Rakesh Ojha

Hello DB sir
thanks for gentle reply
i m not getting the website address from your message on which layout managers are discussed in tutorial. If you mean sun.com then please tell me.
Thanks
Rakesh Ojha

Similar Messages

  • ADF/Swing probles with nested panels layout.

    When panel is placed in other panel, changing of nested panel layout by changing panel properties, results in adding in jbInit() metod code for setting choosen layout at the end of jbInit and not (as in top panel) at the begining of jbInit(). Many times (for instance when layout is BorderLayout) because of this nested panel is displayd empty. It is necessary of course to manually move lines setting layout before lines which adds components to nested panel. Thou it is possible to do it manually it would be nice not to have remember about it.

    Remi,
    how do I reproduce this? Can you give me a step-by-step instruction? Its not clear from your posting which JDeveloper release you are using (though I assume JDeveloper 10.1.3), nor if the panels are created in external Java file or within the parent panel.
    Frank

  • Mouseclick issue on nested panel

    Hi all,
    I'm redesigning my portfolio website with Spry sliding panel
    tech. and I've encountered a behaviour issue that I was wondering
    if anybody else has seen before.
    So I've got one set of sliding panels that controls the
    sections of the website you visit (ie graphic design, web design
    etc) and then a repeating panel inside each one that displays the
    different examples in each genre. This nested panel is controlled
    by the simple nextFrame(), prevFrame() functionality (as well as
    listing the number of panels that are also clickable for more
    direct navigation) - to see it all in action, visit
    http://www.pixelz.co.uk/newhome.html
    My problem is that the FIRST time you click on a navigation
    link in the nested panel, nothing happens. After that it all works
    fine, but it almost seems that the panel needs to be focused on
    first by a click and then will run as normal. Anybody else come
    across this issue? Is there a fix for it?
    Cheers
    Pix

    Hi all, anybody found a workaround for this problem?
    still searching...

  • Nested panels and bkg image

    Hi,
    I have a JPanel inside another one. It hides when I click on "close" ("fermer" in French, below).
    I'd like now add a background image to the parent panel (the background panel), so that the child panel appears in the middle of this image.
    To make a long story short, my centered panel is okay without background image but disappears when I try and subclass JPanel (paint method) in order to get a back-panel-with image.
    You'll find the code I use below. Is there any way to achieve this ?
    Thanks for your help !
    public class testCenteredPanel extends javax.swing.JFrame {
        /** Creates new form testCenteredPanel */
        public testCenteredPanel() {
            initComponents();
            setDefaultLookAndFeelDecorated(true);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            java.awt.GridBagConstraints gridBagConstraints;
            jPanel1 = new javax.swing.JPanel();
            jPanel2 = new javax.swing.JPanel();
            jPanel3 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            getContentPane().setLayout(new java.awt.GridBagLayout());
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setLocationRelativeTo(this);
            addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    formMouseClicked(evt);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            jPanel1.setLayout(new java.awt.GridBagLayout());
            jPanel1.setPreferredSize(new java.awt.Dimension(400, 400));
            jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jPanel1MouseClicked(evt);
            jPanel2.setLayout(new java.awt.BorderLayout());
            jPanel2.setBackground(new java.awt.Color(255, 255, 255));
            jPanel2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
            jPanel2.setPreferredSize(new java.awt.Dimension(200, 200));
            jPanel3.setBackground(new java.awt.Color(255, 255, 255));
            jButton1.setText("Fermer");
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
            jPanel3.add(jButton1);
            jPanel2.add(jPanel3, java.awt.BorderLayout.SOUTH);
            jPanel1.add(jPanel2, new java.awt.GridBagConstraints());
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.weighty = 1.0;
            getContentPane().add(jPanel1, gridBagConstraints);
            pack();
        private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {
            jPanel2.setVisible(true);
        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
            jPanel2.setVisible(false);
        private void formMouseClicked(java.awt.event.MouseEvent evt) {
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new testCenteredPanel().show();
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        // End of variables declaration
    }

    Thanks for your answer !
    So far, it is better : I have overriden the paintComponent method insteda of the paint method and the background image shows up. But the "close" button on the nested (centrered) panel doesn't work any longer. I can click on it, but it stays grayed and the panel doesn't hide. I read the articles you pointed out but couldn't find much for this (except opacity, which I experimented without success).
    Here's the code of my centered panel : maybe there's something wrong here ?
    public class CenterPanel extends javax.swing.JPanel {
        /** Creates new form CenterPanel */
        public CenterPanel() {
            initComponents();
       public  boolean isOpaque(){
            return true;
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            setLayout(new java.awt.BorderLayout());
            setBackground(new java.awt.Color(255, 255, 255));
            setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
            setPreferredSize(new java.awt.Dimension(200, 200));
            jPanel1.setBackground(new java.awt.Color(255, 255, 255));
            jPanel1.setOpaque(false);
            jButton1.setText("Acheter");
            jPanel1.add(jButton1);
            jButton2.setText("Fermer");
            jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton2MouseClicked(evt);
            jPanel1.add(jButton2);
            add(jPanel1, java.awt.BorderLayout.SOUTH);
        private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
            hide();
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JPanel jPanel1;
    }

  • Nested Panels: Switching between

    I'm writing a program that has to switch between two panels that are nested in a parent panel. Is anyone there who has done this before and has a workable solution? Thanks in advance...

    Thanks very much, I tried this and this is the error I got when I clicked on the 'proceedBtn' in this case colorBtn...
    Using the content pane, the program does not know where to add the panel, is there a way of directing it to add the panel to the parent panel directly?.. I couldn't find any method that helps in this direction. Thanks again for the help.
    java.lang.Error: Do not use Talk2Me.ChatRoom.add() use Talk2Me.ChatRoom.getContentPane().add() instead
    at javax.swing.JFrame.createRootPaneException(JFrame.java:458)
    at javax.swing.JFrame.addImpl(JFrame.java:484)
    at java.awt.Container.add(Container.java:307)
    at Talk2Me.ChatRoom.colorBtnMouseClicked(ChatRoom.java:257)
    at Talk2Me.ChatRoom.access$100(ChatRoom.java:12)
    at Talk2Me.ChatRoom$2.mouseClicked(ChatRoom.java:190)
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:208)
    at java.awt.Component.processMouseEvent(Component.java:5096)
    at java.awt.Component.processEvent(Component.java:4890)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3598)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3439)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3174)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
    at java.awt.Container.dispatchEventImpl(Container.java:1609)
    at java.awt.Window.dispatchEventImpl(Window.java:1585)
    at java.awt.Component.dispatchEvent(Component.java:3439)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

  • Drawing into a nested panel

    Hello,
    I have an interface consisting of several panels nested together to accept user input on the left and output a shape on the right.
    I have the user input widgets set up the way I want. I am about to add the listeners and handlers to each widget. However, before I do, I want to know how to draw the shape in the panel.
    My code is below. I would like to accept the user input from the entry panel and output a shape (with code yet to be added) to the displayPanel.
    Again, my question is, how do I draw anything into the displayPanel?
    //import the necessary java packages
    import java.awt.*;   //for the awt widgets
    import javax.swing.*;  //for the swing widgets
    import java.awt.event.*;  //for the event handler interfaces
    public class DemoShape extends JApplet
        //declare private data members of the DemoShape class
        //required control buttons
        private JTextField xShapeText, yShapeText, messageText, fontSizeText;
        private ButtonGroup shapeRadio;
        private JRadioButton rect, oval, roundRect;
        private JComboBox shapeColorDrop, fontTypeDrop, fontColorDrop;
        //declare the entry and display panel containers
        private Container entire;
        private JPanel entryPanel, displayPanel;
        //create a text buffer to house the response messge
        String sText = "";
        //declare public data members of the DemoShape class
        //init method to initialize the applet objects
        public void init()
            //arrays of string to be used later in combo boxes
            //some are used more than once
            String fonts[] = {"Dialog", "Dialog Input", "Monospaced",
                                "Serif", "Sans Serif"};
            String shapes[] = {"Rectangle", "Round Rectangle", "Oval"};   
            String colors[] = {"Black", "Blue", "Cyan", "Dark Gray",
                                "Gray", "Green", "Light Gray", "Magenta", "Orange",
                                "Pink", "Red", "White", "Yellow"};
            //declare variables to assist with the layout
            //these are the left and right justified x coordinates
            int ljX = 10; int rjX = 150;
            //this is the y coordinates for the rows
            int yRow1 = 10;     //the shape
            int yRow2 = 40;
            int yRow3 = 60;
            int yRow4 = 130;
            int yRow5 = 150;
            int yRow6 = 210;    //the message
            int yRow7 = 240;
            int yRow8 = 260;
            int yRow9 = 300;
            int yRow10 = 320;
            int yRow11 = 360;
            int yRow12 = 380;
            //these are the widths for the text boxes, drop downs
            //message entry,  big message entry and radio buttons
            int tWidth = 30; int dWidth = 100;
            int mWidth = 125; int bmWidth = 250;
            int rWidth = 125;
            //the height is universal, even for the messages!
            int height = 25;
            //set a content pane for the entire applet
            //set the size of the entire window and show the entire applet
            entire = getContentPane();
            entire.setLayout(new GridLayout(1, 2));
            entire.setSize(800,600);
            //create the entry panel and add it to the entire pane
            entryPanel = new JPanel();
            entryPanel.setLayout(null);
            entire.add(entryPanel);
            //create the display panel and add it to the entire pane
            //this will display the output
            displayPanel = new JPanel();
            displayPanel.setLayout(null);
            entire.add(displayPanel);       
            //entry panel code
            //add the form elements in the form of rows
            //the first row (label)
            JLabel entryLabel = new JLabel("Enter Shape Parameters:");
            entryPanel.add(entryLabel);
            entryLabel.setBounds(ljX, yRow1, bmWidth, height);
            //second row (labels)
            JLabel shapeTypeLabel = new JLabel("Select Shape:");
            shapeTypeLabel.setBounds(ljX, yRow2, mWidth, height);
            entryPanel.add(shapeTypeLabel);
            JLabel shapeColorLabel = new JLabel("Select Shape Color:");
            shapeColorLabel.setBounds(rjX, yRow2, mWidth, height);
            entryPanel.add(shapeColorLabel);
            //third row (entry)        
            rect = new JRadioButton("Rectangle", true);
            oval = new JRadioButton("Oval", false);
            roundRect = new JRadioButton("Round Rectangle", false);
            rect.setBounds(ljX, yRow3, rWidth, height);
            oval.setBounds(ljX, yRow3 + 20, rWidth, height);
            roundRect.setBounds(ljX, yRow3 + 40, rWidth, height);
            shapeRadio = new ButtonGroup();
            shapeRadio.add(rect);
            shapeRadio.add(oval);
            shapeRadio.add(roundRect);
            entryPanel.add(rect);
            entryPanel.add(oval);
            entryPanel.add(roundRect);       
            shapeColorDrop = new JComboBox(colors);
            shapeColorDrop.setBounds(rjX, yRow3, dWidth, height);
            shapeColorDrop.addActionListener(new testListen());
            entryPanel.add(shapeColorDrop);
            //the fourth row (labels)
            JLabel xShapeLabel = new JLabel("Enter Width:");
            xShapeLabel.setBounds(ljX, yRow4, mWidth, height);
            entryPanel.add(xShapeLabel);
            JLabel yShapeLabel = new JLabel("Enter Height:");
            yShapeLabel.setBounds(rjX, yRow4, mWidth, height);
            entryPanel.add(yShapeLabel);
            //the fifth row (entry)
            xShapeText = new JTextField("200", 3);
            xShapeText.setBounds(ljX, yRow5, tWidth, height);
            entryPanel.add(xShapeText);        
            yShapeText = new JTextField("200", 3);
            yShapeText.setBounds(rjX, yRow5, tWidth, height);
            entryPanel.add(yShapeText);
            //the sixth row (label)
            JLabel messageLabel = new JLabel("Enter Message Parameters:");
            messageLabel.setBounds(ljX, yRow6, bmWidth, height);
            entryPanel.add(messageLabel);
            //the seventh row (labels)   
            JLabel messageEntryLabel= new JLabel("Enter Message:");
            messageEntryLabel.setBounds(ljX, yRow7, mWidth, height);
            entryPanel.add(messageEntryLabel);
            //the eighth row (entry)
            messageText = new JTextField(25);
            messageText.setBounds(ljX, yRow8, mWidth, height);
            entryPanel.add(messageText);
            //the ninth row (label)
            JLabel fontTypeLabel = new JLabel("Select Font:");
            fontTypeLabel.setBounds(ljX, yRow9, mWidth, height);
            entryPanel.add(fontTypeLabel);
            JLabel fontColorLabel = new JLabel("Select Font Color:");
            fontColorLabel.setBounds(rjX, yRow9, mWidth, height);
            entryPanel.add(fontColorLabel);
            //the tenth row (entry)
            fontTypeDrop = new JComboBox(fonts);
            fontTypeDrop.setBounds(ljX, yRow10, dWidth, height);
            entryPanel.add(fontTypeDrop);       
            fontColorDrop = new JComboBox(colors);
            fontColorDrop.setBounds(rjX, yRow10, dWidth, height);
            entryPanel.add(fontColorDrop);
            //the eleventh row (label)
            JLabel fontSizeLabel = new JLabel("Select Font Size:");
            fontSizeLabel.setBounds(ljX, yRow11, mWidth, height);
            entryPanel.add(fontSizeLabel);
            //the final row (entry)
            fontSizeText = new JTextField("12", 2);
            fontSizeText.setBounds(ljX, yRow12, tWidth, height);
            entryPanel.add(fontSizeText);
            //display panel code
            //simple test for the display panel
            JLabel test = new JLabel("Display Output Here");
            test.setBounds(10, 10, 150, 25);
            displayPanel.add(test);   
            //set the applet to visible
            entire.setSize(800, 600);
            entire.setVisible(true);
        }   //end the init method
        //declare an inner class to handle the events
        private class testListen implements ActionListener
            //supply the implementation of the actionPerformed method
            //pass an event variable as the argument
            public void actionPerformed(ActionEvent e)
                //get the source of the event
                if(e.getSource() == shapeColorDrop)
                    sText = "shapeColorDrop pushed!";
                    JOptionPane.showMessageDialog(null, sText);
            }   //end actionPeformed method
        }   //end testListen class
    }   //end DemoShape class

    Ok, I realize you need a canvas to draw into. Now how to I draw into this canvas.
    //import the necessary java packages
    import java.awt.*;   //for the awt widgets
    import javax.swing.*;  //for the swing widgets
    import java.awt.event.*;  //for the event handler interfaces
    public class DemoShape extends JApplet
        //declare private data members of the DemoShape class
        //declare the entry and display panel containers
        private Container entire;       //houses the entryPanel and displayCanvas
        private JPanel entryPanel;      //accepts the user entries into widgets
        private Canvas displayCanvas;   //displays the response of the user entries
        //required control buttons for the entryPanel
        private JTextField xShapeText, yShapeText, messageText, fontSizeText;
        private ButtonGroup shapeRadio;
        private JRadioButton rect, oval, roundRect;
        private JComboBox shapeColorDrop, fontTypeDrop, fontColorDrop;
        //declare public data members of the DemoShape class
        //init method to initialize the applet objects
        public void init()
            //arrays of string to be used later in combo boxes
            //some are used more than once
            String fonts[] = {"Dialog", "Dialog Input", "Monospaced",
                                "Serif", "Sans Serif"};
            String shapes[] = {"Rectangle", "Round Rectangle", "Oval"};   
            String colors[] = {"Black", "Blue", "Cyan", "Dark Gray",
                                "Gray", "Green", "Light Gray", "Magenta", "Orange",
                                "Pink", "Red", "White", "Yellow"};
            //declare variables to assist with the layout
            //these are the left and right justified x coordinates
            int ljX = 10; int rjX = 150;
            //this is the y coordinates for the rows
            int yRow1 = 10;     //the shape rows
            int yRow2 = 40;
            int yRow3 = 60;
            int yRow4 = 130;
            int yRow5 = 150;
            int yRow6 = 210;    //the message rows
            int yRow7 = 240;
            int yRow8 = 260;
            int yRow9 = 300;
            int yRow10 = 320;
            int yRow11 = 360;
            int yRow12 = 380;
            //these are the widths for the text boxes, drop downs
            //message entry,  big message entry and radio buttons
            int tWidth = 30; int dWidth = 100;
            int mWidth = 125; int bmWidth = 250;
            int rWidth = 125;
            //the height is universal, even for the messages!
            int height = 25;
            //set a content pane for the entire applet
            //set the size of the entire window and show the entire applet
            entire = this.getContentPane();
            entire.setLayout(new GridLayout(1, 2));
            entire.setSize(800,600);
            //create the entry panel and add it to the entire pane
            entryPanel = new JPanel();
            entryPanel.setLayout(null);
            entire.add(entryPanel);
            //create the display canvas and add it to the entire pane
            //this will display the output
            displayCanvas = new Canvas();
            entire.add(displayCanvas);       
            //entry panel code
            //add the form elements in the form of rows
            //the first row (label)
            JLabel entryLabel = new JLabel("Enter Shape Parameters:");
            entryPanel.add(entryLabel);
            entryLabel.setBounds(ljX, yRow1, bmWidth, height);
            //second row (labels)
            JLabel shapeTypeLabel = new JLabel("Select Shape:");
            shapeTypeLabel.setBounds(ljX, yRow2, mWidth, height);
            entryPanel.add(shapeTypeLabel);
            JLabel shapeColorLabel = new JLabel("Select Shape Color:");
            shapeColorLabel.setBounds(rjX, yRow2, mWidth, height);
            entryPanel.add(shapeColorLabel);
            //third row (entry)        
            rect = new JRadioButton("Rectangle", true);
            oval = new JRadioButton("Oval", false);
            roundRect = new JRadioButton("Round Rectangle", false);
            rect.setBounds(ljX, yRow3, rWidth, height);
            oval.setBounds(ljX, yRow3 + 20, rWidth, height);
            roundRect.setBounds(ljX, yRow3 + 40, rWidth, height);
            shapeRadio = new ButtonGroup();
            shapeRadio.add(rect);
            shapeRadio.add(oval);
            shapeRadio.add(roundRect);
            entryPanel.add(rect);
            entryPanel.add(oval);
            entryPanel.add(roundRect);       
            shapeColorDrop = new JComboBox(colors);
            shapeColorDrop.setBounds(rjX, yRow3, dWidth, height);
            shapeColorDrop.addActionListener(new testListen());
            entryPanel.add(shapeColorDrop);
            //the fourth row (labels)
            JLabel xShapeLabel = new JLabel("Enter Width:");
            xShapeLabel.setBounds(ljX, yRow4, mWidth, height);
            entryPanel.add(xShapeLabel);
            JLabel yShapeLabel = new JLabel("Enter Height:");
            yShapeLabel.setBounds(rjX, yRow4, mWidth, height);
            entryPanel.add(yShapeLabel);
            //the fifth row (entry)
            xShapeText = new JTextField("200", 3);
            xShapeText.setBounds(ljX, yRow5, tWidth, height);
            entryPanel.add(xShapeText);        
            yShapeText = new JTextField("200", 3);
            yShapeText.setBounds(rjX, yRow5, tWidth, height);
            entryPanel.add(yShapeText);
            //the sixth row (label)
            JLabel messageLabel = new JLabel("Enter Message Parameters:");
            messageLabel.setBounds(ljX, yRow6, bmWidth, height);
            entryPanel.add(messageLabel);
            //the seventh row (labels)   
            JLabel messageEntryLabel= new JLabel("Enter Message:");
            messageEntryLabel.setBounds(ljX, yRow7, mWidth, height);
            entryPanel.add(messageEntryLabel);
            //the eighth row (entry)
            messageText = new JTextField(25);
            messageText.setBounds(ljX, yRow8, mWidth, height);
            entryPanel.add(messageText);
            //the ninth row (label)
            JLabel fontTypeLabel = new JLabel("Select Font:");
            fontTypeLabel.setBounds(ljX, yRow9, mWidth, height);
            entryPanel.add(fontTypeLabel);
            JLabel fontColorLabel = new JLabel("Select Font Color:");
            fontColorLabel.setBounds(rjX, yRow9, mWidth, height);
            entryPanel.add(fontColorLabel);
            //the tenth row (entry)
            fontTypeDrop = new JComboBox(fonts);
            fontTypeDrop.setBounds(ljX, yRow10, dWidth, height);
            entryPanel.add(fontTypeDrop);       
            fontColorDrop = new JComboBox(colors);
            fontColorDrop.setBounds(rjX, yRow10, dWidth, height);
            entryPanel.add(fontColorDrop);
            //the eleventh row (label)
            JLabel fontSizeLabel = new JLabel("Select Font Size:");
            fontSizeLabel.setBounds(ljX, yRow11, mWidth, height);
            entryPanel.add(fontSizeLabel);
            //the final row (entry)
            fontSizeText = new JTextField("12", 2);
            fontSizeText.setBounds(ljX, yRow12, tWidth, height);
            entryPanel.add(fontSizeText);
            //display panel code
            //set the applet to visible
            entire.setSize(800, 600);
            entire.setVisible(true);
        }   //end the init method
        //begin the paint method to the canvas
        public void paint(Graphics g)
            //how do I draw into the displayCanvas?????
        }   //end the paint method
    }   //end DemoShape class

  • Gui using nested panels???

    hello all i am trying to do a gui and i have been building it in pieces using panels . However once i get to the point of adding the panels to the frame they have already been nested several times. My problem is now accessing the things in the panels like the textfrields and the buttons to set and get text and eventhandlers. Is this a bad way to go about doing Swing design? Should i just layout everyting onto one panel.? what is considered good practice in gui design using swing?

    Hi All,
    I ve just started hacking the Swing library, and I am facing the same problem, and to make more clear, here is my scenario:
    public class PaperEntry extends JFrame {
         public static Paper paper;
         Publisher publisher;
         JLabel titleLabel, dateLabel, conference_nameLabel;
         JTextField titleField, dateField, conference_nameField, authorNameField,
                   autherAddressField, publisherNameField, publisherAddressField;
         TextArea displayArea;
         JButton addAuthorButton, addPublisherButton, showPaperButton, exitButton;
         public PaperEntry() {
              super("Paper Information");
              paper = new Paper();
              Container c = getContentPane();
         public void displayPaper() {
              displayArea.setText(paper.toString());
         public static void main(String[] args) {
              PaperEntry p = new PaperEntry();
              p.setSize(420, 450);
              p.show();
         private class ActionEventHandler implements ActionListener {
              public void actionPerformed(ActionEvent e) {
                   if(e.getSource() == exitButton)
                        System.exit(0);
                   else if(e.getSource() == addAuthorButton) {
                        AuthorEntry ae = new AuthorEntry();
                        ae.show();
    THE PROBLEM...
    // Author Entry is almost of the same structure as PaperEntry and I want to stop PaperEntry from
    // proceeding until I exit out from the AuthorEntry with the an object Author to be added to the Paper
    // object
                   else if(e.getSource() == addPublisherButton) {
                        PublisherEntry pe = new PublisherEntry();
                        pe.show();                    
                   else if(e.getSource() == showPaperButton) {
                   paper.setTitle(titleField.getText());
                   paper.setConference_name(conference_nameField.getText());
                   paper.setDate(dateField.getText());
                   //System.out.println(paper.toString());
                   displayPaper();
    public class AuthorEntry extends JFrame {
    // author info entering frame
    public class PublisherEntry extends JFrame {
    // publisher info entering frame
    I am looking for any solutions....
    cu
    modber

  • Panel in swing

    i want to display all the forms in a project within the same panel while clicking appropriate button

    Start here: [Creating a GUI with JFC/Swing|http://java.sun.com/docs/books/tutorial/uiswing/]

  • Nested Panels with SpringLayout

    I've been attempting to use nested JPanels, each with a SpringLayout. However, this seems to cause some very strange behaviour with component scrolling off the left edge of the window unless it's sized narrow. I've not used SpringLayout much, but I'm at a loss to explain it.
    I have:
        protected void setUpGUI() {
            //set up layout
            SpringLayout theLayout=new SpringLayout();
            super.getContentPane().setLayout(theLayout);
            //add EntryPane
            super.getContentPane().add(theEntryPane);
            theLayout.putConstraint(SpringLayout.NORTH,theEntryPane,5,SpringLayout.NORTH,super.getContentPane());
            theLayout.putConstraint(SpringLayout.WEST,theEntryPane,5,SpringLayout.WEST,super.getContentPane());
            theLayout.putConstraint(SpringLayout.EAST,super.getContentPane(),5,SpringLayout.EAST,theEntryPane);
            //set up buttons
            storeButton=new JButton("Store");
            refreshButton=new JButton("Refresh");
            //add buttons
            super.getContentPane().add(storeButton);
            theLayout.putConstraint(SpringLayout.NORTH,storeButton,5,SpringLayout.SOUTH,theEntryPane);
            theLayout.putConstraint(SpringLayout.WEST,storeButton,5,SpringLayout.WEST,super.getContentPane());
            theLayout.putConstraint(SpringLayout.SOUTH,super.getContentPane(),5,SpringLayout.SOUTH,storeButton);
            super.getContentPane().add(refreshButton);
            theLayout.putConstraint(SpringLayout.NORTH,refreshButton,5,SpringLayout.SOUTH,theEntryPane);
            theLayout.putConstraint(SpringLayout.WEST,refreshButton,5,SpringLayout.EAST,storeButton);
            theLayout.putConstraint(SpringLayout.SOUTH,super.getContentPane(),5,SpringLayout.SOUTH,refreshButton);
        }In my subclass of JFrame, and 'theEntryPane' is a subclass of JPanel which includes the following:
        protected void addComponent(Component comp){
            add(comp);
            theLayout.putConstraint(SpringLayout.WEST,comp, 5,SpringLayout.WEST,this);
            theLayout.putConstraint(SpringLayout.EAST,this,5,SpringLayout.EAST,comp);
            if(lastComponent==null){
                theLayout.putConstraint(SpringLayout.NORTH,comp,5,SpringLayout.NORTH,this);
            } else {
                theLayout.putConstraint(SpringLayout.NORTH,comp,3,SpringLayout.SOUTH,lastComponent);
            lastComponent=comp;
        }My subclass of JFrame has a similar method that simply passes the component on to theEntryPane. When I run it and add the following components:
    addComponent(new JLabel("Thing!"));
            addComponent(new JLabel("Thing!"));
            addComponent(new JLabel("Thing!"));The buttons at the bottom are off to the left, and only return when you make the window narrow. If I make my nested pane override getPreferredSize() to return Integer.MAX_VALUE for both dimensions, the buttons at the bottom (which are in a different container!) appear correctly but the top two labels in the nested frame suffer from the same problem.
    Can anyone shed any light onto what's going on here? It appears that the nested layouts are somehow interfering with one another.

    Found the error. Fixed now.

  • Controlling Of Panels In Swing

    Hi,.. i have two jpanels in same frame i have divided the panels as left frame and right frame so when i click
    a component for example a button in left frame a GUI should appear on right frame and when i click another component
    in left frame the earlier GUI should disappear and new GUI with other components should appear i mean new panel on the right side shoud
    appear and the left Panel should be there itself how can i do that plz help...

    Dayananda B V wrote:
    you should go through the following linkThe question is ~5 months old and the OP never responded to the question asked - better focus on ACTIVE questions (which are 999/1000 times RECENT questions) if you don't want to waste your time. If you can't find one here, there are always dozens of questions to answer over on stackoverflow.

  • JDom + XML (nested tags) + JTree (Swing)

    I have an XML file that looks like this:
    <root>
      <subtree>
        <a name="John Doe">Here is one big string with information about john doe</a>
        <a name="Tom Smith">Another string</a>
      </subtree>
      <subtree>
        <subtree>
            <a name="abc">mlsjkfqm</a>
        </subtree>
        <subtree>
            <a name="def">qsmdlfkj</a>
             <subtree>
                <a name="ghi">mqsldjkf</a>
                <a name="jkl">mqlsdfjkq</a>
             </subtree>
        </subtree>
      </subtree>
    </root>I want to have this XML file viewed in a JTree. I was told I should use a JTreeModel to store the data in, and org.JDom to parse the data and put them in the JTreeModel. But I still don't see how...
    Can anyone please put me in the right direction, or give some examples of similar examples?
    (I found examples on the web, but they all use trees like <root><node>qsdf</node><node>qsfqsdf</node><node>...</node></root>, so no nested nodes, and I have a difference between <subtree> and <a>...)
    Thanks in advance!

    I want to have this XML file viewed in a JTree. I was
    told I should use a JTreeModel to store the data in,
    and org.JDom to parse the data and put them in the
    JTreeModel. But I still don't see how...
    By writing an Adapter, a JDOMTreeModel class that implements TreeModel by using the JDOM API. Then, you could instantiate a JTree from that JDomTreeModel...

  • Problems calling nested panels

    Hi there I've been going round in circles trying to figure this out. I have a jframe which is split in two, two seperate classes add content to each panel. I have a a mouse listener in one of these classes which I want to use to update the other panel in the other class. I don't know how to reference the other class though!
    Can someone put me in the right direction?
    thanks

    alshac,
    One way to do this is to pass into the mouselistener object a reference to the other object. You may do this in the constructor, or after the fact. This approach may produce undesirable coupling.
    Alternatively add the mouselistener object as a listener to the other class, or to its contained panel.
    --A                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Nested Panel Grid

    Hi,
    I have a page contains panelgroup -> panelgrid -> 4panelgrid.
    First Row X1Y1,X2Y1 and second row X2Y1,X2Y2.
    X1Y1 column size is equal to X2Y1,X2Y2.I want to align the same way i.e
    X1Y1 X2Y1
    X2Y2
    X1Y2
    I tried css style vertical align:top also tried in columnclass.
    But I unable to align proper way.We used Microsoft filter dropshadow in the style class.
    Please let me know how to resolve this problem.
    Thanks

    I didn't used table probs(our apps standards).Please see the sample code.
    <h:panelGroup id="groupId" >
         <h:panelGrid columns="2" align="center" id="gridId" >
              <h:panelGrid columns="1" cellpadding="2" cellspacing="0">
              </h:panelGrid >
              <h:panelGrid columns="2" cellpadding="2" cellspacing="0"
                   style="vertical-align: top; filter:progid:DXImageTransform.Microsoft.dropshadow(sprobs)">
              </h:panelGrid >
              <h:panelGrid columns="2" cellpadding="2" cellspacing="0"
                   style="vertical-align: top; filter:progid:DXImageTransform.Microsoft.dropshadow(sprobs)">
              </h:panelGrid>
              <h:panelGrid columns="3" cellpadding="2" cellspacing="0" >
              </h:panelGrid>
         </h:panelGrid>                
    <h:panelGroup>

  • Updating different panels in Swing?

    I have a JTabbedPane with panel1, panel2, panel3
    and a JButton in panel1. I know I need to addActionListener, etc, but what code would change the display of panel3? (Let's say I just want to display a new JLabel there; ie "Button pressed")
    Thanks

    Use indexOftab(String) to get the tab index based on the caption of the tab you want.
    Use setSelectedIndex(String) to select the tab based on the index you specify.
    Use getSelectedComponent() to get the component from the selected tab, such as a JPanel. Then add a JLabel with the caption to this component.
    Look at: http://java.sun.com/docs/books/tutorial/uiswing/components/tabbedpane.html for more info
    Hope this helps.
    Riz

  • Listen for an events for Swing objects in a separate class?

    Hi all, sorry if this is in the wrong section of the forum but since this is a problem I am having with a Swing based project I thought i'd come here for help. Essentially i have nested panels in separate classes for the sake of clarity and to follow the ideas of OO based development. I have JPanels that have buttons and other components that will trigger events. I wish for these events to effect other panels, in the Hierachy of my program:
    MainFrame(MainPanel(LeftPanel, RightPanel, CanvasPanel))
    Sorry I couldnt indent to show the hierarchy. Here LeftPanel, RightPanel and CanvasPanel are objects that are created in the MainPanel. For example i want an event to trigger a method in another class e.g. LeftPanel has a button that will call a method in CanvasPanel. I have tried creating an EventListner in the MainPanel that would determine the source and then send off a method to the relevant class, but the only listeners that respond are the ones relevant to the components of class. Can I have events that will be listened to over the complete scope of the program? or is there another way to have a component that can call a method in the class that as an object, it has been created in.
    Just as an example LeftPanel has a component to select the paint tool (its a simple drawing program) that will change a color attribute in the CanvasPanel object. Of course I realize i could have one massive Class with everything declared in it, but I'd rather learn if it is possible to do it this way!
    Thanks in advance for any help you can offer
    Lawrence
    Edited by: insertjokehere on Apr 15, 2008 12:24 PM

    Thanks for the response, ive added ActionListneres in the class where the component is, and in an external class. The Listeners work inside the class, but not in the external class
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    public class LeftPanel extends JPanel implements ActionListener {  
        /* Constructing JButtons, null until usage of the constructor */
        JButton pencilBut;
        JButton eraserBut;
        JButton textBut;
        JButton copyBut;
        JButton ssincBut;
        JButton ssdecBut;
        ActionListener a = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.print("\nNot supported yet.");
        /* The Top Panel contains the title of program */
        public LeftPanel(Dimension d){
            /* Sets up the layout for the Panel */
            BoxLayout blo = new BoxLayout(this,BoxLayout.Y_AXIS);
            this.setLayout(blo);
            /* Sets Up the Appearance of the Panel */
            this.setMinimumSize(d);
            this.setBackground(Color.RED);
            this.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
            /* Pencil Tool */
            pencilBut = new JButton("Pencil");
            pencilBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            pencilBut.setActionCommand("pencil");
            pencilBut.addActionListener(a);
            this.add(pencilBut);
            /* Eraser Tool */
            eraserBut = new JButton("Eraser");
            eraserBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            eraserBut.addActionListener(a);
            this.add(eraserBut);
            /* Text Tool */
            textBut = new JButton("Text");
            textBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            textBut.addActionListener(a);
            this.add(textBut);
            /* Copy Previous Page */
            copyBut = new JButton("Copy Page");
            copyBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            copyBut.addActionListener(a);
            this.add(copyBut);
            /* Stroke Size Increase */
            ssincBut = new JButton("Inc");
            ssincBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            ssincBut.addActionListener(a);
            this.add(ssincBut);
            /* Stroke Size Decrease */
            ssdecBut = new JButton("Dec");
            ssdecBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            ssdecBut.addActionListener(a);
            this.add(ssdecBut);
            System.out.print("\nLeftPanel Completed");
        public void actionPerformed(ActionEvent e) {
            System.out.print("\nAction Performed");
        }But this is not picked up in my external class here
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    public class MainPanel extends JPanel implements ActionListener {
        /* Creates a new the main JPanel that is used in the FlipBookFrame to contain all of the elements */
        public MainPanel(){
            /* TopPanel constraints*/
            tpcs.gridx = 1;
            tpcs.gridy = 0;
            tpcs.gridwidth = 1;
            tpcs.gridheight = 1;
            tpcs.fill = GridBagConstraints.BOTH;
            tpcs.weightx = 0.0;
            tpcs.weighty = 1.0;
            /* LeftPanel Constraints*/
            lpcs.gridx = 0;
            lpcs.gridy = 0;
            lpcs.gridwidth = 1;
            lpcs.gridheight = 3;
            lpcs.fill = GridBagConstraints.BOTH;
            lpcs.weightx = 1.0;
            lpcs.weighty = 1.0;
            /* CentrePanel Constraints*/
            cpcs.gridx = 1;
            cpcs.gridy = 1;
            cpcs.gridwidth = 1;
            cpcs.gridheight = 1;
            cpcs.fill = GridBagConstraints.NONE;
            cpcs.weightx = 0.0;
            cpcs.weighty = 0.0;
            /* RightPanel Constraints*/
            rpcs.gridx = 2;
            rpcs.gridy = 0;
            rpcs.gridwidth = 1;
            rpcs.gridheight = 3;
            rpcs.fill = GridBagConstraints.BOTH;
            rpcs.weightx = 1.0;
            rpcs.weighty = 1.0;
            /* BottomPanel Constraints*/
            bpcs.gridx = 1;
            bpcs.gridy = 2;
            bpcs.gridwidth = 1;
            bpcs.gridheight = 1;
            bpcs.fill = GridBagConstraints.BOTH;
            bpcs.weightx = 0.0;
            bpcs.weighty = 1.0;   
            this.setLayout(gblo);   //Sets the Layout of the panel to a GridBagLayout
            this.add(tp, tpcs); //Adds the TopPanel to the MainPanel using the TopPanel layout
            this.add(lp, lpcs); //Adds the LeftPanel to the MainPanel using the LeftPanel layout
            this.add(cp, cpcs); //Adds the CanvasPanel to the MainPanel using the CanvasPanel layout
            this.add(rp, rpcs); //Adds the RightPanel to the MainPanel using the RightPanel layout
            this.add(bp, bpcs); //Adds the BottomPanel to the MainPanel using the BottomPanel layout
            gblo.layoutContainer(this); //Lays Out the Container
        public PanelSizes getPanelSizes(){
            return ps;
        public void actionPerformed(ActionEvent e) {
            System.out.print("\nExternal Class finds event!");
            /*String command = e.getActionCommand();
            if (command.equals("pencil")){
                System.out.print("\nYESSSSSSSSSSSSSSSSSSSSS!");
        /* Create of objects using the PanelSizes funtions for defining the */
        PanelSizes ps = new PanelSizes();   //Creates a new PanelSizes object for sizing the panel
        CanvasPanel cp = new CanvasPanel(ps.getCentrePanelDimension()); //Creates a new Canvas Panel
        TopPanel tp = new TopPanel(ps.getHorizontalPanelDimension()); //Creates the TopPanel
        BottomPanel bp = new BottomPanel(ps.getHorizontalPanelDimension()); //Creates the BottomPanel
        LeftPanel lp = new LeftPanel(ps.getVerticalPanelDimension()); //Creates the LeftPanel
        RightPanel rp = new RightPanel(ps.getVerticalPanelDimension());   //Creates the RightPanel
        /* I have chosen to create individual constraints for each panel to allow for adding of all
         components a the end of the constructor. This will use slightly more memory but gives clarity
         in the code */
        GridBagConstraints cpcs = new GridBagConstraints();
        GridBagConstraints tpcs = new GridBagConstraints();
        GridBagConstraints bpcs = new GridBagConstraints();
        GridBagConstraints lpcs = new GridBagConstraints();   
        GridBagConstraints rpcs = new GridBagConstraints();
        GridBagLayout gblo = new GridBagLayout();
    }Any help will be greatly appreciated :-)

Maybe you are looking for

  • Can I buy something from a certain store over the phone?

    Say there is a deal on tomorrow with the 5s, can I ring up my local store and pay over the phone? Or can I reserve it....

  • Temporary text on billing document and delivery

    Dear all, I have the following question: Is it possible to add a temporary text on the billing doc and delivery doc? For example: 'Closed between Christmas & New year' thanks, Ton

  • Aggregate function max

    hi evrybdy can we use MAX aggregate  function to pick a field of type char from database table ...if yes thn how ..? plzzz ans soon . thank u .

  • OpenTTD missing dependency.

    I am running x86_64 arch installation with 2.6.32 kernel. When I try to start the game nothing happens. In console I get this output: $ openttd openttd: error while loading shared libraries: libicuuc.so.44: cannot open shared object file: No such fil

  • Where to find oracle.sql Java definitions

    Where do I find the definitions for the oracle.sql Java methods? I'm looking for something like the Sun Java web guide (i.e. http://java.sun.com/j2se/1.3/docs/api/) Mike Sullivan null