How to add component to JPanel

Hello,
I Try to add a JPnel to other JPnel
but it works not ther is a error in this code ??
class MyClass extends JFrame
    Container contentPane;
  public MyClass()
              contentPane = this.getContentPane();
              contentPane.setBorderLayout(new BorderLayout());
             MainPanel();
puplic void MainPanel()
     Dimension dim = new Dimension(w,h);
     Dimension aDim = new Dimension((w / 2),(h / 2));
     JPanel mainPanel = JPanel();
     mainPanel.setPrefferedSize(dim);
     mainPanel.setLayout(new BorderLayout());
     JPanel pp = getLanguagePanel(aDim);
     pp.revalidate();
     mainPanel.add(pp,BorderLayout.PAGE_END);
     mainPanel.revalidate();
     contentPane.add(mainPanel,BoderLayout.CENTER)
public JPanel getLanguagePanel(Dimension aDim)
         JPanel retPanel = new JPanel();
     retPanel.setPreferredSize(aDim);
     retPanel.setBorder(null);
     JLabel L = new JLabel("Test Label");
     L.setBounds(50,50,250,30);
     retPanel.add(L);
     retPanel.setBackground(Color.GREEN);
     retPanel.setOpaque(true);
     retPanel.revalidate();
     retPanel.repaint();
     return retPanel;
}thanks

contentPane.setBorderLayout(...)There is no such method. Your compiler should be telling you this.
puplic void MainPanel()There is no such modifier. Your compiler should be telling you this.
mainPanel.setPrefferedSize(...)There is no such method. Your compiler should be telling you this.
BoderLayout.CENTERThere is no such class. Your compiler should be telling your this.

Similar Messages

  • How to drop component on JPanel

    Hi,
    i want to drop some component on JPanel.I'm talking about drag n drop concept, but how to apply it on JPanel.
    For eg how to drag n drop an image from your tool bar to a JPanel.
    Thanks in advance.

    Hi,
    thanks for ur reply.
    But this link is not helping me much...more idea needed....actually my question is to use 'JPanel' to drop component....how to make it work?and also how to resize the component itself by streaching it's border ( something like taht )
    thanks...
    Edited by: DJgpmax on Jun 17, 2008 2:10 AM

  • How to add component dynamically to datatable row?

    Hi,
    I have a dropdown in one column of table.Depending upon selected value in that dropdown, I want to add some components dynamically only in that row.How to do this?
    I have seen that findComponent() method doesnt accept clientId.Is there any other way to use clientId to search components. Because clientIds contain row numbers.
    Thanks in advance,
    Chitra.

    Bind the component to the bean using its 'binding' attribute. Then use it instead.

  • Add component to JPanel

    Hello everyone,
    I have a JComboBox, and when i select an Option i would like to add a new component to the JPanel (just below the JComboBox). This is what i have at the moment, but i must be doing something wrong because it does nothing.
    String[] choices = { "Choose option", "Option 1", "Option 2", "Option 3", "Option 4", "Option 5" };
                       mainPanelComponent5 = new JComboBox(choices );
                       mainPanelComponent5.setBounds(100, 70, 150, 20);
                       mainPanelComponent5.addItemListener(new ItemListener() {
                          public void itemStateChanged(ItemEvent e) {
                              if (e.getStateChange() == ItemEvent.SELECTED) {
                                   JLabel compId = new JLabel("TEST");
                                   compId.setBounds(210, 70, 250, 20);
                                   mainPanel.add(compId);
                      });Any help? thanks in advance

    mainPanel.revalidate();Thank you, it works

  • How to add separator on JPanel?

    How do you add a separator on a JPanel like shown on the following screen shot?:
    http://www.carpenterdev.com/scrn.jpg
    Thanks,
    --BobC                                                                                                                                                                                                                                                                               

    Thanks! I'll do that - upperPanel JSeparator lowerPanel; Makes sense.
    --BobC                                                                                                                                                                                   

  • How to add component to production order like co08

    Hi experts,
         i used FM CO_BC_INSERT_CMP_OF_ORDERS ,code as follows:
    TCOKT_IMP-AUTYP = '10'.
    TCOKT_IMP-MANDT = SY-MANDT.
    RESBB_INS-MANDT = SY-MANDT.
    RESBB_INS-MATNR = 'NTQA3070'.
    RESBB_INS-POSTP = 'L'.
    RESBB_INS-VORNR = '0010'.
    RESBB_INS-AUFNR = ORDER_NUMBER.
    RESBB_INS-POSNR = '0010'.
    RESBB_INS-BDMNG = 19.
    RESBB_INS-RGEKZ = 'X'.
    RESBB_INS-WERKS = '1110'.
    *RESBB_INS-LGORT = HEADER-PRODUCTION_SCHEDULER.
    *RESBB_INS-RSNUM = HEADER-RESERVATION_NUMBER.
    RESBB_INS-RSPOS = '0010'.
    APPEND RESBB_INS.
    CALL FUNCTION 'CO_BC_INSERT_CMP_OF_ORDERS'
    EXPORTING
    FLG_CALC_CHK            = 'X'
      INS_MODE                = ' '
       NO_RSPOS_COUNT          = 'X'
       TCOKT_IMP               = TCOKT_IMP
       FLG_BANF_CREATE         = 'X'
      I_FLG_COPY_LTEXT        = 'X'
      TABLES
        RESBB_INS               = RESBB_INS
    EXCEPTIONS
       NO_AMOUNT               = 1
       NO_BWVAR                = 2
       NO_KLVAR                = 3
       NO_VALUE                = 4
       RELEASE_NO_CHANGE       = 5
       SYSTEM_ERROR            = 6
       OTHERS                  = 7
    but i still can't add the component to an exist production order.i think maybe i missed some important parameters,I need your help .Thanks a lot.

    I'm not sure what you are trying to do.
    Would you like to overlay the two components and display only one at a time? If so then just put them both in a Canvas at the same position and change their "visible" properties as necessary.
    You should be able to do this in MXML, except for the switching part, which will likely be in AS.
    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    www.ChikaraDev.com
    Flex / AIR Development, Training, and Support Services

  • How to add scrollbar to jpanel

    i created a jpanel with images & related text to images, which repaints dynamically according to width,now i wann to add a vertical scrollbar to it.
    plz..help me

    iam getting scrollbar but iam unable to get scrolling when i change the size
    my code like this....
    //here iam using jpanel to get images and text
    public class ImgNtext extends JPanel {
       public ImgNtext(){
           //to intialize values
           init_values();
      public void init_values{
       //In these init_values iam decalaring imageFile name & text using hashtable
       public void paintComponent(Graphics g) {
             super.paintComponent(g);
             //getting width of screen
             int gw = getWidth();
             //then iam retriving all the values using while loop
             while(i.hasMoreElements())
                        //accroding to width iam painting the components
                          if(gw<100){
                               g.drawImage(image,x,y,null);
                               g.drawString(string,x,y+80);
                               gw -=100;
                               x += 100;
                         else{
                               y += 100;
                               gw = getWidth();
    public class ImagePanel
           ImgNtext it = new ImgNtext();
           JScrollPane sp;
           public ImagePanel() {
                     JFrame jf = new JFrame();
                     jf.setSize(1000,1000);
                     scp = new                JScrollPane(it,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                     jf.getContentPane().add(scp);
                     jf.setVisible(true);
              public static void main(String s[]){
                   ImagePanel img = new ImagePanel();
    }

  • How to add Component in JList

    Hello guys,
    I want to add a components that is for eg (checkBox,CompoBox) in JList
    Pls help me
    Thanks in advance
    aneesh

    I want to add a components that is for eg
    (checkBox,CompoBox) in JList Uhm, maybe you should redesign your GUI. I can understand adding that stuff to a JTable, but a JList with combo boxes makes me sick. It's like having a button with radiobuttons on it...

  • How to add a text Component ( text annotation) to the Tiff Image

    Hi.............
    This is the first time I am using Sun Developers Forum.......................
    My problem is.............I want to add a component ( Text or Label ) to the Tiff Image which is displayed on the JIMICanavs [ from JIMI API ].
    Even , if anybody knows about How to add a component to the JIMICanavs , Please help me..................................

    I'm curious: is JIMI still popular? What advantange does it have over the current Java 2D support in the J2SE, or over JAI?

  • How to add a new url link in a view of an existing webdynpro component?

    How to add a new url link in a view of an existing webdynpro component?

    hi ,
    refer SAP online hep :
    Implementing Enhancements in a View
    http://help.sap.com/erp2005_ehp_04/helpdata/EN/46/233f2189f74f08e10000000a114a6b/frameset.htm
    To enhance the layout of the view, you can create new UI elements. This procedure is no different u2013 from a technical viewpoint u2013 from creating UI elements in components themselves. All UI elements created within the enhancement implementation can then be processed as usual.
    Enhancements  means inserting user developments into SAP development objects at predefined positions.
    The Enhancement Framework enables you to add functionality to standard SAP software without actually changing the original repository objects, and to organize these enhancements as effectively as possible.
    refernce :
    have a look at this article
    How to Create Enhancement Implementation in Web Dynpro ABAP
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/700317da-bd79-2c10-368e-8f18bf5d8b81&overridelayout=true
    as pointed correctly by Saurav in earlier thread
    regards,
    amit

  • How to add an image to the JPanel

    i have been searching for many to add in an iamge to the JPanel...but with error..can anyone kndly help?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class adv extends JPanel {
    ImageIcon pic = new ImageIcon("home.gif");
    public void paintComponent(Graphics g) {
    g.drawImage(pic,0,0,this);
    super.paintComponent(g);
    public static void main(String[] args) {
    adv mpg= new adv();
    mpg.setLayout(new GridLayout(5,1,15,15));
         JFrame window = new JFrame ("dv");
    window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);     
    window.add(mpg);
    window.setVisible(true);
    window.setSize (550,225);
    }

    i have try out the suggestion that u have provided...still with error...wat can i do to solve it? any other way?
    below is how i add to my program...
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class adv extends JPanel {
        ImageIcon pic = createImageIcon("home.gif");
        public void paintComponent(Graphics g) {
      super.paintComponent(g);
    g.drawImage(pic.getImage(),0,0,this);
        public static void main(String[] args) {
           /*adv mpg= new adv();
          mpg.setLayout(new GridLayout(5,1,15,15));
             JFrame window = new JFrame ("dv");
             window.setLayout(new BorderLayout());
             frame.add(mpg, BorderLayout.CENTER);
           window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);     
           window.add(mpg);
           window.setVisible(true);
           window.setSize (550,225);*/
           adv mpg = new adv();
           JFrame frame = new JFrame();
         frame.setLayout(new BorderLayout());
         frame.add(pic, BorderLayout.CENTER);
         frame.setSize(500, 500);
         frame.setVisible(true);
    }

  • How to add an image to a JPanel ?

    hi,
    do you now how to add an image to a JPanel ?
    thanks a lot !

    You can either use the Graphics method drawImage from the panel's paintComponent(Graphics g) method, or you can create an ImageIcon, with your Image in its constructor. And then create a JLabel, passing that ImageIcon in its constructor. Then, you can simple use the panel.add() method to add that JLabel.
    For using the paintComponent method, check out the thread already posted above (I'll type it in again just in case)
    http://forum.java.sun.com/thread.jsp?forum=31&thread=288769
    If you want to use a JLabel, you can do something like this:
    Image img;
    JLabel label = new JLabel(new ImageIcon(img));
    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout());
    panel.add(label);Val

  • How to add an image in a JPanel

    Hi All,
    How to add an image in a JPanel and make it display.
    Thanks,

    I have tried with the below code. If I there is any fault please correct me.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class HomePage extends JFrame implements     ActionListener {
        JButton cmdClick;
        JLabel label;
        JPanel homePanel = new JPanel();
        JPanel headPanel = new JPanel();
        JPanel btPanel = new JPanel();
        private JPanel mainPanel = new JPanel(new CardLayout());
        CardLayout cl;
        CalScenario calcFrame = null;
        public HomePage() {
           setTitle("Test Kit");
           setSize( 1008,399);
           setBackground( Color.gray );
           setResizable(false);
           Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
           Rectangle window = getBounds();
           setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
           setVisible(true);
            homePanel.setLayout(new BorderLayout());
            headPanel.setPreferredSize(new Dimension(1008,153));
            label = new JLabel("Main menu");
            headPanel.add(label);
            headPanel.setBackground(Color.CYAN);
            ImageIcon icon = new ImageIcon("images/slash.gif");
            JLabel imglabel = new JLabel();
            imglabel.setIcon(icon);
            headPanel.add(label);
            this.getContentPane().add(headPanel);
            btPanel.setBackground(Color.ORANGE);
            cmdClick = new JButton("Click here");
            btPanel.add(cmdClick);
            cmdClick.addActionListener(this);
            homePanel.add("North",headPanel);
            homePanel.add("West",btPanel);
            calcFrame = new CalScenario(mainPanel);
            mainPanel.add(homePanel, "HomePanel");
            mainPanel.add(calcFrame, "CalcFrame");
            cl = (CardLayout) (mainPanel.getLayout());
            add(mainPanel);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void actionPerformed(ActionEvent source)  {
          if (source.getSource() == (JButton) cmdClick) {
                cl.show(mainPanel, "CalcFrame");
        public static void main( String args[]) {
             HomePage homeFrame = new HomePage();
             homeFrame.setVisible(true);
    }

  • How to add adf faces in component pallete of jdeveloper 11g?

    how to add adf faces in component pallete of jdeveloper 11g?

    Hi,
    the replacement of ADF Faces HTML components in JDeveloper 11 is Trinidad. For existing applications, a migration path will be provided in JDeveloper 11 production. I wouldn't recommend configuring ADF Faces in JDeveloper 11.
    You an configure ADF Faces Components in JDeveloper 11 by :
    - Tools --> Manage Libraries
    - Create a User Library
    - select ADF Faces adf-faces-impl.jar
    - Enure the namespace is not af or afh but something different to not cnflic with teh ADF Faces RC components
    Note that adding the ADF Faces components to the component palette will not make them show in the ADF binding context menu nor will it automaticaly set up the web.xml file. The components are available as any other JSF library set
    Again, I wouldn't go this way ;-)
    Frank

  • How to add interface to customlize MXML Component when use Flex Builder 3?

    How to add interface to customlize MXML Component when use
    Flex Builder 3?

    David,
    I don't believe you can add the interface via the creation
    dialog in FlexBuilder 3. You can always manually add the
    "implements" property to your MXML Component root tag. Something
    like this: <mx:VBox implements="com.mycorp.IMyInterface">
    If you want autogeneration of the interface, then create an
    ActionScript class with that interface and then copy the generated
    functions and setter/getters into the script block of your MXML
    component.

Maybe you are looking for