Class extends JPanel ? help

i have a class that extends JPanel and i have all my buttons , textfields created on it.
so how do i call the class to display the panel on a frame?
asuming class is the class that extends JPanel
class newPanel = new class();
f.contentPane.add(newPanel);
is this the right way?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Yeah... that works fine, just call f.show(). Mind your LayoutManager....

Similar Messages

  • Can any one change this Applet into a class that extends Jpanel.....

    Hi,
    I need this applet as a class that extends JPanel, I will be very very thankful to you if any one kindly change this Applet code into a class that extends JApplet.
    I will be very thankful to you if some one can reserve few minutes & do this favor early.
    Thanks a lot for any help.
         My Pong Code
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.awt.event.*;
    public class Class1 extends Applet implements Runnable
    {     private final int APPLET_WIDTH = 900;
         private final int APPLET_HEIGHT = 600;
         private int px = 15;
         private final int py = 560;
         private final int ph = 10;
         private final int pw = 75;
         private int old_px = px;
         private int bx = 450;
         private int by = 15;
         private final int bh = 20;
         private final int bw = 20;
         private int move_x = 2;
         private int move_y = 2;
         private boolean done = false;
         Thread t;
         private final int delay = 25;
         public void init()
         {     setBackground(Color.black);
              setSize(APPLET_WIDTH, APPLET_HEIGHT);
              requestFocus();
              addKeyListener(new DirectionKeyListener());
             (t = new Thread(this)).start();
         public void run()      {
        try      {     while((t == Thread.currentThread()) && (done == false))           {     
                   if ((bx < 15) || (bx > APPLET_WIDTH-30))                     move_x = -move_x;                                if ((by < 15) ||                    ((by > APPLET_HEIGHT-60)&&                     ((px<=bx)&&(bx<=px+pw))))
                        move_y = -move_y;
                   if (by > APPLET_HEIGHT)
                        done = true;
                                   bx = bx + move_x;
                   by = by + move_y;                                                repaint();
                   t.sleep(delay);
         catch(Exception e)      {}
         }//end run
         /*public void move_paddle(int amount)
              old_px = px;
              //if (amount > 0)
                //if (px <= APPLET_WIDTH-15)
                   px = px + amount;
              //else if (amount < 0)
               // if (px >= 15)
                   px = px + amount;
         public void paint(Graphics page)
              //     page.setColor(Color.black);
              //     page.drawRect(old_px, py, pw, ph);
                   page.setColor(Color.blue);
                   page.drawRect(px, py, pw, ph);
                   page.setColor(Color.white);
                   page.drawOval(bx, by, bw, bh);
                   if ((done == true) && (by > APPLET_HEIGHT))
                        page.drawString("LOSER!!!", APPLET_WIDTH/2, APPLET_HEIGHT/2);
                   else if (done == true)
                        page.drawString("Game Over, Man!", APPLET_WIDTH/2-10, APPLET_HEIGHT/2);
         private class DirectionKeyListener implements KeyListener               
              public void keyPressed (KeyEvent event)
                   switch (event.getKeyCode())
                   case KeyEvent.VK_LEFT:
                        old_px = px;
                        if (px >=15)
                             px -=10;
                        break;
                   case KeyEvent.VK_RIGHT:
                        old_px = px;
                        if (px+pw <= APPLET_WIDTH-15)
                             px += 10;
                        break;
                   case KeyEvent.VK_Q:
                        done = true;
                   default:
                   }  //end switch
                   repaint();
              }//end keyPressed
              public void keyTyped (KeyEvent event)
              public void keyReleased (KeyEvent event)
         }  //end class 
    }

    thank you sir for your advice.
    Its not like that I without any attempt, just past code here & asked for its conversion. I spent about 5 hours on it, can say spoil whole day but to no avail. You then just guide me, give some hint so that I do it. I will most probably wanted to do it by myself but asked for help when was just disappointed.
    I try to put all init() in default constructor of identical copy of this applet that extends JPanel. Problem.....ball tend to fell but pad not moving. Also out out was not getting ant color input. That was like my best effort.....other tried that I found by search like just do nothing only extend panel OR frame in spite of applet, start applet from within main of another class.... these are few I remember what I tried.
    I will be very very thankful to you if you can help/guide me how can I do it. Behavior of the Applet is like a normal PONG game with on pad controlled by arrow keys, & one ball colliding with walls of boundary & falling down.
    Thanks a lot again for your attention & time.

  • JEditorPane (or subclasses) and a class that extends JPanel

    hello to all,
    i'm realizing an application with Swing.
    i have realized a class that extends JPanel(called "PanelLayer") and, other to draw a ruler as Office 2003, it must contain an other subclass of JPanel (called "PanelLayer") that, in turn, will contain a JEditorPane.
    the problem is strange: i should continue in moviment the mouse to look well the JEditorPane (or subclasses)
    the URL is a image of the result that i get...
    URL : http://phantom89.helloweb.eu/img/img.jpg
    codes:
    public class Layer extends JPanel implements ComponentListener{
        private static final long serialVersionUID = 1L;
        private Rectangle2D.Double areaCentrale = new Rectangle2D.Double(100,100,850,1285);
        private double larghFoglio = 21.0*50;
        private double altFoglio = 29.7*50;
        private double zoom = 1.0;
        private JScrollPane sp = new JScrollPane(this);
        private Rectangle2D.Double posFoglio = new Rectangle2D.Double();
        private int lastX,lastY;
        private PanelLayer pl;
        private Point mouse = null;
        private JEditorPane text;
        public Layer(PanelLayer pl){
            this.setLayout(null);
            this.pl = pl;
            this.setPreferredSize(new Dimension((int)(40+larghFoglio*zoom), (int)(100+altFoglio*zoom)));
            areaCentrale = new Rectangle2D.Double(100*zoom,100*zoom,850*zoom,1285*zoom);
                sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
            sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            //try{
                text = new JEditorPane();
                text.setBounds(50,50,200,200);
                this.add(text);
            //}catch(IOException e){}
            lastX = sp.getHorizontalScrollBar().getValue();
            lastY = sp.getVerticalScrollBar().getValue();
            this.addComponentListener(this);
            this.addMouseListener(this);
            this.addMouseMotionListener(this);
        public void paintComponent(Graphics g){
            if(posFoglio.height + posFoglio.width == 0){
                this.posFoglio = new Rectangle2D.Double((this.getWidth()-larghFoglio*zoom)/2,50,larghFoglio*zoom,altFoglio*zoom);       
            Graphics2D g2d = (Graphics2D)g;
            g2d.setPaint(Color.lightGray);
            g2d.fillRect(0,0,this.getWidth(),this.getHeight());
            g2d.translate((this.getWidth()-larghFoglio*zoom)/2,50);
            g2d.setPaint(Color.black);
            g2d.draw(new Rectangle2D.Double(0,0,larghFoglio*zoom,altFoglio*zoom));
            g2d.setPaint(Color.white);
            g2d.fill(new Rectangle2D.Double(1,1,larghFoglio*zoom-1,altFoglio*zoom-1));
            g2d.setPaint(Color.blue);
            g2d.draw(areaCentrale);
        public JScrollPane getJScrollPane(){
            return sp;
        public Rectangle2D.Double getDimFoglio(){       
            return this.posFoglio;
        public double getCmWidth(){
            return larghFoglio*zoom/50+((larghFoglio*zoom/50)%1 <= getIncr() ? 0 : getIncr());
        public double getCmHeight(){
            return altFoglio*zoom/50+((altFoglio*zoom/50)%1 <= getIncr() ? 0 : getIncr());
        public Point getPointMouse(){
            return mouse;
        public void refresh(){
            lastX = sp.getHorizontalScrollBar().getValue();
            posFoglio.x = (this.getWidth()-larghFoglio*zoom)/2-lastX;
        public double getIncr(){
            return zoom/2;
        public void mouseClicked(MouseEvent e) {}
        public void mouseEntered(MouseEvent e) {}
        public void mouseExited(MouseEvent e) {}
        public void mousePressed(MouseEvent e) {}
        public void mouseReleased(MouseEvent e) {}
        public void mouseDragged(MouseEvent e) {}
        public void mouseMoved(MouseEvent e) {
            mouse = e.getPoint();
            mouse.x -= sp.getHorizontalScrollBar().getValue();
            mouse.y -= sp.getVerticalScrollBar().getValue();
            pl.repaint();
        public void componentHidden(ComponentEvent e) {}
        public void componentMoved(ComponentEvent e) {
            lastX = sp.getHorizontalScrollBar().getValue();
            posFoglio.x = (this.getWidth()-larghFoglio*zoom)/2-lastX;
            lastY = sp.getVerticalScrollBar().getValue();
            posFoglio.y = 50-lastY;
            pl.repaint();
        public void componentResized(ComponentEvent e) {
            this.repaint();
            pl.repaint();
        public void componentShown(ComponentEvent e) {}
    public class PanelLayer extends JPanel implements MouseWheelListener,MouseInputListener{
        private static final long serialVersionUID = 1L;
        private Layer layer;
        private JScrollPane sp = null;
        private boolean visualizzaMouse = false;
        public PanelLayer(){
            this.setLayout(null);
            layer = new Layer(this);
            layer.addMouseListener(this);
            layer.addMouseMotionListener(this);
        public void paintComponent(Graphics g){
            if(layer.getDimFoglio().getWidth()+layer.getDimFoglio().getHeight() == 0){
                layer.setSize(50,50);
            if(sp == null){
                sp = layer.getJScrollPane();
                sp.addMouseWheelListener(this);
                sp.setBounds(30,30,this.getWidth()-30,this.getHeight()-30);
                this.add(sp);
            }else{
                layer.refresh();
            sp.setBounds(30,30,this.getWidth()-30,this.getHeight()-30);
            Graphics2D g2d = (Graphics2D)g;
            g2d.setPaint(new Color(153,255,153));
            g2d.fill(new Rectangle2D.Double(0,0,this.getWidth(),30));
            g2d.fill(new Rectangle2D.Double(0,0,30,this.getHeight()));
            g2d.setPaint(Color.black);
            g2d.drawLine(0,0,this.getWidth(),0);
            g2d.drawLine(0,30,this.getWidth(),30);
            g2d.drawLine(0,0,0,this.getHeight());
            g2d.drawLine(30,0,30,this.getHeight());
            for(double i=0,j=0;i<=layer.getCmWidth();i+=layer.getIncr(),j++){
                if(j%2==0){
                    g2d.drawLine((int)(layer.getDimFoglio().x+31+i*50), 15,(int)(layer.getDimFoglio().x+31+i*50), 30);
                    g2d.drawString(String.valueOf((int)(j/2)), (float)(layer.getDimFoglio().x+31+i*50), 13);               
                }else{
                    g2d.drawLine((int)(layer.getDimFoglio().x+31+i*50), 22,(int)(layer.getDimFoglio().x+31+i*50), 30);
            for(double i=0,j=0;i<=layer.getCmHeight();i+=layer.getIncr(),j++){
                if(j%2==0){
                    g2d.drawLine(15, (int)(layer.getDimFoglio().y+31+i*50),30,(int)(layer.getDimFoglio().y+31+i*50));
                    g2d.drawString(String.valueOf((int)(j/2)),5,(float)(layer.getDimFoglio().y+31+i*50));
                }else{
                    g2d.drawLine(22, (int)(layer.getDimFoglio().y+31+i*50),30,(int)(layer.getDimFoglio().y+31+i*50));
            if((layer.getPointMouse() != null)&&(visualizzaMouse)){
                g2d.drawLine(layer.getPointMouse().x+30,0,layer.getPointMouse().x+30,30);
                g2d.drawLine(0,layer.getPointMouse().y+30,30,layer.getPointMouse().y+30);
            g2d.setPaint(new Color(153,255,153));
            g2d.fillRect(1,1,29,29);
            int largh = layer.getJScrollPane().getVerticalScrollBar().getWidth();
            g2d.fillRect(this.getWidth()-largh, 1, largh, 29);
            g2d.fillRect(1, this.getHeight()-largh, 29, largh);
        public void mouseWheelMoved(MouseWheelEvent e) {
            JScrollBar vsb = layer.getJScrollPane().getVerticalScrollBar();
            vsb.setValue(vsb.getValue()+20*e.getWheelRotation());
        public void refresh(){
            if((layer != null)&&(sp != null)){
                layer.setSize(this.getWidth()-30,this.getHeight()-30);
                sp.setViewportView(layer);
                this.repaint();
        public void mouseClicked(MouseEvent e) {}
        public void mouseEntered(MouseEvent e) {
            visualizzaMouse = true;
            repaint();
        public void mouseExited(MouseEvent e) {
            visualizzaMouse = false;
            repaint();
        public void mousePressed(MouseEvent e) {}
        public void mouseReleased(MouseEvent e) {}
        public void mouseDragged(MouseEvent e) {}
        public void mouseMoved(MouseEvent e) {}
    }(my english isn't very good)

    Don't really understand what the posted code does and I can't execute the code so I don't have much to offer.
    But I did notice that you don't invoke super.paintComponent(...) which means you may have garbage being painted on the panels.
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
    http://homepage1.nifty.com/algafield/sscce.html

  • Xml Serializing a class that extends JPanel

    Alright I am getting an Exception saying java.
    java.lang.reflect.InvocationTargetException
    Continuing ...
    java.lang.Exception: XMLEncoder: discarding statement XMLEncoder.writeObject(JpanelScreen);
    Continuing ...
    is anyone familiar with this... It ocurrs when I try to Serialize my class object that extends JPanel...

    any examples of how to do this?
    try {
    java.beans.XMLEncoder out = new java.beans.XMLEncoder( new BufferedOutputStream( new java.io.FileOutputStream(getFilename())));
    out.writeObject(Screen);
    out.close();
    }catch (Exception exc) {System.err.println(exc.getMessage());}

  • Closing a class that extends JPanel

    Hi, i have a class that extends JPanel(lets call it class A). In that class, if the user click the logout button, i want class A to close and display class B that extends JFrame. right now, i am able to call class B, but i cannot close class A.
    I uses remove() to close class A, but it doesnt work... could u tell me what to do??
    I put this code in class A...
    if (e.getSource() == logoutButton)     {
         remove(this);
         new Rest_Login1();
         String [] ar = null;
         Rest_Login1.main(ar);
    } Thx

    so i want to remove the CustomerPanel3 and display the Rest_Login1...
    some of my code look like this.
    thx
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class CustomerPanel3 extends JPanel implements ActionListener
    // some JButton, JLabel n etc
         public void actionPerformed (ActionEvent e)
              if (e.getSource() == logoutButton)     {
                   remove(this);
                   new Rest_Login1();
                   String [] ar = null;
                   Rest_Login1.main(ar);
    public class Rest_Login1 {
         public static void main(String args[])
              JFrame login1 = new JFrame("Login User Interface");
              JFrame.setDefaultLookAndFeelDecorated(true);
              RestaurantLogin userpan = new RestaurantLogin();
              login1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              login1.setSize(600, 250);
              login1.setLocation(230,192);
              login1.getContentPane().add(userpan);
              login1.setVisible(true);
    }

  • Extended JPanel not rendering correctly

    I am using a split pane. One pane is a JScrollPane with a JTree attached, the second is a JScrollPane with a JPanel attached. The idea is to show different panels in the second pane depending on which node of the tree is selected.
    My problem is that I when I select a node on my tree in the first panel, my second panel shows only a small grey square.
    My extended JPanel class is:
    public class onePanel extends JPanel {
    public void onePanel() {
    JLabel jLabel1 = new JLabel();
    jLabel1.setText("Node One");
    add(jLabel1);
    In my main I am calling:
    JPanel info = new JPanel();
    JScrollPane myScrollPane = new JScrollPane(info);
    onePanel op = new onePanel();
    info.removeAll();
    info.add(op);
    info.revalidate();
    Any help on this matter would be much appreciated. Let me know if you need more information. Thanks.
    Fox

    My boss helped me with this one as well as bharatchhajer . I'll post the answer for future reference:
    I made the change suggested by bharatchhajer to leave out the intermediate info panel and just deal directly with the JScrollPane.
    In the subclass, instead of using the default constructor OnePanel(), I passed the parent. In this case, OnePanel(myScrollPane).
    I added this to the subclass:
    myScrollPane.add(this);
    Also, instead of myScrollPane.add(info); I used:
    OnePanel op = new OnePanel();
    op.OnePanel(myScrollPane);
    myScrollPane.setViewportView(op);
    So the main problem was that my subclass had no idea about what to attach to. The handle or parent had to be passed to it.
    Fox

  • I want to make gImage Class extends Image and use Graphics2D

    Sorry, my english short...
    I want to make gImage Class extends Image and use Graphics2D
    I trying to do...
    make class gImage..
    extends Image class. (Inheritance)
    but Image class is abstract class..
    And I want to use gImage class same as Image class.
    I can't use constructor... because by Abstract calss...
    How do i?
    Help me.. plz...
    And I want to use Graphics2D at Applet Game, But not use Java JDK Plug-in...
    No Way?

    You need to use BufferedImage with 2D or RenderedImage with JAI.
    BufferedImage effectivley extends an Image so you can
    draw it to screen in paintCOmponent.
    I use an Extended JPanel to draw an image in a Panel with this.
    MArk

  • Unwanted space within an extended JPanel

    Hello JDC
    I subclass the Jpanel and I draw an image inside. The problem is that I receive unwanted empty space in the canvas bounds. I tried to set the mini,maxi and preferred size of both the jframe and the canvas but its doesnt help.
    public class ImageCanvas extends JPanel{
      static Image thisImg=null;
      static URL url=null;
      static Toolkit tool=null;
      public static final String DEFAULTADDRESS = "http://127.0.0.1/image/def.gif";
      public static final  boolean PRINTLN=true;
      public  static void p(String out){
        if(PRINTLN)
          System.out.println(out);
      // constructs a
      public ImageCanvas(String filepath){
         setLayout(new BorderLayout());
         try{
          url = new URL(filepath);
        }catch(Exception e){
          System.out.println("problem with creating url :" + e.toString());
        thisImg = Toolkit.getDefaultToolkit().getImage(url);
      public ImageCanvas(){
        try{
          url = new URL(DEFAULTADDRESS);
        }catch(Exception e){
          System.out.println("problem with creating url :" + e.toString());
        thisImg = Toolkit.getDefaultToolkit().getImage(url);
        repaint();
      public void setPic(Image x){
        //System.out.println("ImageCanvas > setPit(Image) invoked");
        thisImg = x;
        repaint();
      public static Image makeImage(String path){
        try{
          url = new URL(path);
        }catch(Exception e){
          System.out.println("problem with creating url :" + e.toString());
        Image img = Toolkit.getDefaultToolkit().getImage(url);
        return img;
      public void paintComponent(Graphics g){
        g.drawImage(thisImg,0,0,this);
    public void update(Graphics g){
        paint(g);
      public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.getContentPane().add(new ImageCanvas());
          frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
              System.exit(0);
        frame.pack();
        frame.setVisible(true);
    }the image dimension 100x100
    Any replies will by imprecated
    Shay Gaghe

    You could try using JLabel instead of subclassing JPanel. Just set the label's icon and don't set any text.
    I also agree that GridBagLayout is the most useful layout. When I was new to Java programming it was the most confusing. In order to do complicated graphical interfaces I use to have to use a lot of nested panels with different layouts. Even then I had problems because I couldn't specify exactly which component should expand etc. Now, two years later and after becoming a Sun certified programmer for the Java 2 platform, I use GridBagLayouts almost always and it give me the most flexibility. It allows me to make some really professional gui programs. I recommend spending some time getting used to using GridBagLayout more.

  • 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!

  • Constructing a class extending JDialog when invoked from main application

    In an application that extends JFrame a method, showJDialogGUI, is called to instantiate an object of another class (called enterGUI) that extends JDialog. This object, enterGUIDialog, is modal; user must click on its Submit button in order to dismiss it and be able to continue in MainProgram. I have troubles getting error messages resolved when the constructor of the enterGUIDialog JDialog object is called. Perhaps there are other things wrong with below code. Any help appreciated - snippet of code from both classes is below.
    public class MainProgram extends JFrame {
    enterGUI enterGUIDialog; // declaration for object of class extending JDialog
    public MainProgram() {     // constructor
    myContainer = getContentPane();
    showJDialogGUI(); // calls method to initialize
    public void showJDialogGUI() {
    enterGUIDialog = new enterGUI (this, true);
    enterGUIDialog.setDefaultCloseOperation (DISPOSE_ON_CLOSE );
    enterGUIDialog.setSize(200,200);
    enterGUIDialog.setVisible( true );
    enterGUIDialog.show();
    } // end of class MainProgram
    public class enterGUI extends JDialog{
    Container myContainer;
    JPanel myPanel;
    //// How to call the constructor to create this JDialog????
    public loginGUI( JRootPane theRoot, boolean theModal ) // passed in 'this', and 'true'
    // or maybe??? public About(Frame parent, boolean modal) {
    this.setRootPane( theRoot ); //???????
    // or maybe ??? super(theRoot, flag);
    //super(theRoot, flag); // calls Dialog class constructor
    this.setModal( theModal ); // ?????
    myContainer = getContentPane();
    myContainer.setLayout( new FlowLayout() );
    thePanel = new JPanel();
    // next add components to JPanel, then add to the JDialog container
    fieldsPanel.add( pageLabel ); etc.
    myContainer.add( fieldsPanel );
    // etc.
    myContainer.setDefaultCloseOperation( DISPOSE_ON_CLOSE );
    myContainer.setVisible(true);
    } // end of constructor
    // more methods etc
    }

    Error received is:
    E:\Ghost>
    MainProgram.java:670: cannot resolve symbol
    symbol : constructor enterGUI (MainProgram,boolean)
    location: class MyPackage.enterGUI
    enterGUIDialog = new enterGUI(this, true);
    'new enterGUI(this, true); ' seems to be at start of
    error
    TIAThe error message could not be any more clear. To wit: the compiler is telling you it cannot find a constructor for class enterGUI that takes as parameters a reference to a javax.swing.JFrame, and a boolean value. Supply the constructor and the error will not be raised.

  • How to use logging in the actions classes extends standart actions?

    Hello!
    I have some action classes extends standart actions, for example Z_ExtMaintainBasketDispatcherAction extends MaintainBasketDispatcherAction. I tried to use logging functionality in my classes but there were no my lines in log and trace files.
    For example I added followed lines in basketPerform() method of Z_ExtMaintainBasketDispatcherAction:
    boolean isDebugEnabled = log.isDebugEnabled();
    if(isDebugEnabled){
    log.debug("++++++++++++++++ Test tracing in B2B_SNG. ++++++++++++++++");
    but in there was no such line neither in log file nor in trace file.
    How I can use logging functionality in my own classes? I need it for tracing and logging.
    CRM 5.0
    regards, Lev

    Well, here is solution. I created a log formatter and log destination like this:
    <log-formatters>
    <log-formatter name="application_sap.com/crm~b2b" type="TraceFormatter" pattern="%d,%-3p %t %s %l %m"/>
    </log-formatters>
    <log-destinations>
    <log-destination name="application_sap.com_crm.b2b" type="FileLog"
        count="10" effective-severity="ALL" limit="10000000" pattern=".\log\applications\isa_ru.log">
    <formatter-ref name="application_sap.com/crm~b2b"/>
    </log-destination>
    </log-destinations>
    and new log controller like this:
    <log-controller effective-severity="ALL" name="ru.sng.isa">
    <associated-destinations>
    <destination-ref name="application_sap.com_crm.b2b" association-type="LOG"/>
    </associated-destinations>
    </log-controller>
    in file META-INF\log-configuration.xml
    Thanks everybody for help!
    Regards, Lev.

  • Class extends JComponent how to use custom methods?

    I have a class Block which extends JPanel
    code is hereprivate class Block extends JLabel{
              boolean top;
              Block(int a,Color c){
                   setSize(40 + a*10,20);
                   setBorder(BorderFactory.createMatteBorder(40+a*10,0,0,0,c));
              void setTop(boolean b){
                   this.top = b;
              boolean getTop(){
                   return top;
         }I need to use getTop() method of certain block in class implementing MouseMotionListener
    I used getComponent() method like this
    e.getComponent().getTop()but it didn't work and gave
    HanoiTowers.java:59: cannot find symbol
    symbol : method getTop()
    location: class java.awt.Component
    if(e.getComponent().getTop()){}
    error
    Is there some other way to do this?

    Antti_ wrote:
    I have a class Block which extends JPanelahem, I believe that it extends JLabel.
    Is there some other way to do this?You could cast I suppose:
              Component c = e.getComponent();
              if (c instanceof Block)
                System.out.println(((Block)c).getTop());
              }

  • Problem using extended JPanel

    Hi, I'm using JDeveloper 10.1.3.3. I've extended JPanel and named it TestPanel, and then have added few textboxes, one checkbox and one combobox. It was created as runnable panel. When I run that panel, everything worked fine. I used it in custom JFrame instead of dataPanel:
    TestPanel dataPanel = new TestPanel();
    Whatever I did, I couldn't see components on that custom panel. I tried to rebuild, run frame, I couldn't see it.
    Then I've tried to create another panel in original dataPanel (JPanel, BorderLayout), and use TestPanel that way. Didn't work. Does anyone know what might be the problem?

    Colleague helped me.
    Created custom panel is placed in Components View as ADF Swing Regions -> view.TestPanel, so it can be dragged and dropped.
    If creating panel in code, after creating custom JPanel
    TestPanel dataPanel = new TestPanel();
    There must be this line in jbInit() method:
    testPanel1.bindNestedContainer(panelBinding.findNestedPanelBinding("TestPanelPageDef1"));

  • Locate a JPanel in an other JPanel (HELP !!!)

    I add the class affectation (see below) in a JPanel but I can't succeed in locating it in this JPanel..
    I have tried to use setLocate and setBounds but it doesn't work
    public class Affectation extends JPanel{
    public Affectation(int deb, int fin,Color couleur){
    this.setBackground(couleur);
    this.setBorder(BorderFactory.createLineBorder(Color.black));
    //this.setBounds(new Rectangle(deb,10,fin-deb,20));
    this.setLocation(deb, 7);
    this.setPreferredSize (new Dimension(fin-deb,20));
              this.setMinimumSize (new Dimension(fin-deb,20));
              this.setMaximumSize (new Dimension(fin-deb,20));
    }

    Here's an example that uses absolute positioning to get a drag effect:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
        public Test () {
            Dimension sizeA = new Dimension (300, 300);
            Dimension sizeB = new Dimension (300, 300);
            DragPanel dragPanelA = new DragPanel (sizeA, new Rectangle (100, 100, 100, 100), Color.YELLOW);
            DragPanel dragPanelB = new DragPanel (sizeB, new Rectangle (100, 100, 100, 100), Color.GREEN);
            WrapPanel wrapPanelA = new WrapPanel (sizeA, dragPanelA, Color.GREEN);
            WrapPanel wrapPanelB = new WrapPanel (sizeB, dragPanelB, Color.YELLOW);
            getContentPane ().setLayout (new GridLayout (1, 2));
            getContentPane ().add (wrapPanelA);
            getContentPane ().add (wrapPanelB);
            setDefaultCloseOperation (DISPOSE_ON_CLOSE);
            setResizable (false);
            setTitle ("Drag those panels!");
            pack ();
            setLocationRelativeTo (null);
            show ();
        private class WrapPanel extends JPanel {
            private Dimension size;
            public WrapPanel (Dimension size, Component component, Color background) {
                this.size = size;
                setLayout (null);
                add (component);
                setBackground (background);
            public Dimension getPreferredSize () {
                return size;
        private class DragPanel extends JPanel {
            private Dimension outerSize;
            private Rectangle bounds;
            public DragPanel (Dimension outerSize, Rectangle bounds, Color background) {
                this.outerSize = outerSize;
                this.bounds = bounds;
                setBounds (bounds);
                setBackground (background);
                DragListener dragListener = new DragListener ();
                addMouseListener (dragListener);
                addMouseMotionListener (dragListener);
            private class DragListener implements MouseListener, MouseMotionListener {
                private Point previousPoint;
                public DragListener () {
                    previousPoint = null;
                public void mousePressed (MouseEvent event) {
                    previousPoint = event.getPoint ();
                public void mouseReleased (MouseEvent event) {
                    previousPoint = null;
                public void mouseDragged (MouseEvent event) {
                    Point point = event.getPoint ();
                    int dx = point.x - previousPoint.x;
                    int dy = point.y - previousPoint.y;
                    bounds.x = getBetween (bounds.x + dx, 0, outerSize.width - bounds.width);
                    bounds.y = getBetween (bounds.y + dy, 0, outerSize.height - bounds.height);
                    setBounds (bounds);
                private int getBetween (int value, int lower, int upper) {
                    return (value < lower) ? lower : (value > upper) ? upper : value;
                public void mouseClicked (MouseEvent event) {}
                public void mouseEntered (MouseEvent event) {}
                public void mouseExited (MouseEvent event) {}
                public void mouseMoved (MouseEvent event) {}
        public static void main (String[] parameters) {
            new Test ();
    }Alternatively, you could create a super wrap panel (or something similar) to place the wrap panels in.
    Kind regards,
      Levi

  • How can a class extending MouseAdapter override mouseDragged method?

    I've found this code from somewhere, don't remember where
    private class DragLimiter extends MouseAdapter {
    @Override
    public void mousePressed(MouseEvent e) {
    pressedX = e.getX();
    pressedY = e.getY();
    @Override
    public void mouseDragged(MouseEvent e) {
    label.setLocation(
    Math.min(
    Math.max(label.getX() + e.getX() - pressedX, BORDER),
    panel.getWidth() - label.getWidth() - BORDER),
    Math.min(
    Math.max(label.getY() + e.getY() - pressedY, BORDER),
    panel.getHeight() - label.getHeight() - BORDER));
    }The question is how can a class extending MouseAdapter override mousedragged()?
    I found that MouseAdapter implements MouseListener whose subinterface is MouseMotionListener, I think this has something to do with the question.
    But I've always thought you can only override methods of the super classes or interfaces not vice versa.
    I believe I have some kind of fundamental misunderstanding of this and would like to have some help in understanding this.
    Thanks

    This is more a Java question than a Swing question.
    I found that MouseAdapter implements MouseListener whose subinterface is MouseMotionListenerThat's not correct: if you look at MouseAdapter Javadoc, you'll find that it implements both MouseListener and MouseMotionListener (and MouseMotionListener is not a subinterface of MouseListener).
    Regardless, if you look at the javadoc, you see that MouseAdapter declares a method public void mouseDragged(MouseEvent). It doesn't matter whether this is also declared by an interface, a subclass can override it all the same.

Maybe you are looking for

  • Error calling stored procedure from MFC using odbc

    Hello, I am using MFC to call a stored procedure written in PL/SQL, but when I make the call I get the next error in Spanish: "No se enlazaron columnas antes de llamar a SQLFetchScroll o SQLExtendedFetch", which more or less in English means: "No row

  • I can't open Final Cut Pro x after it crushed

    I can't open anymore Final Cut Pro X after it crushed while I was editing footage for 10 minutes. Can you tell the reason and what could I do to resolve it? Thank you

  • Keyboard problems on a Macbook Pro Retina 15 Inch

    Here's a new one for the absolute Geniuses out there. I recently had a battery repair on my Macbook Pro Retina Display, which was successful. After using my computer normally for another week, my keyboard has become ill. My RIGHT SHIFT key doesn't wo

  • Downloaded songs in grey

    I just downloaded songs that I purchased on my emac, and they synced to both my ipod and ipad but show up in grey on my mac, saying they are awaiting downloading, but its been over an hour....

  • AVCHD and external hard drive

    Can video from an AVCHD camcorder be imported directly into a G Raid 1 or 2 TB external hard drive? If so, does it need to be formatted first or can that be done in FC after using Intermediate Codec? Thank you