Access to buttons in a extended JPanel!!

I'm making a GUI and my problem is that I can not access buttons in an extended JPanel from the GUI class.
I want to have access to these buttons so that when one click on them, they can perform some event to the components in the GUI class.

I have a a GUI that contains a splitpane. In one of these panels I have a JTable MyJTable that contains a panel MyJPanel with buttons ( edit and remove buttons).
When I click on one of these buttons, the rightpanel in the splitpane is going to change to a different panel.
The problem is that the MyJPanel inside the MyJTable has to extend JPanel. The result of this is that I can not change panels in the rightPanel. This is because MyJPanel inside MyJTable does not contain any reference to the rightPanel.
I have put a the rightpanel in the constructor like this: MyJTable( rightPanel, .., ..) but I think it gets a little bit messy..
It is a bit hard to explain, but I hope you will understand it.

Similar Messages

  • I've installed Mavericks on my Mac Pro. It works well, generally, but will not stay sleeping! Pressing the power button twice sometimes extends the sleep mode but even that seldom results in a full overnight sleep.  File sharing off. What else can help?

    I've installed Mavericks on my Mac Pro. It works well, generally, but will not stay asleep! Pressing the power button twice sometimes extends the sleep mode but even that seldom results in a full overnight sleep.  File sharing off. What else can help?

    Hi fremley,
    Thanks for visiting Apple Support Communities.
    This article may be helpful with determining why your Mac Pro doesn't stay in sleep mode:
    Mac OS X: Why your Mac might not sleep or stay in sleep mode
    http://support.apple.com/kb/HT1776
    Some things reset the sleep timers, preventing the computer from sleeping:
    Hard drive access (even if you're not using the computer, a running application might be accessing your drive, such as when downloading a large file or listening to music in iTunes)
    Moving the mouse or using a portable Mac's trackpad, pressing a mouse button, or pressing a key on the keyboard
    Some System Preferences settings (see below)
    Open applications (see below)
    Input devices (see below)
    Expansion cards (see below)
    Additional drives, such as USB, FireWire, DVD, or CD drives (see below)
    Best Regards,
    Jeremy

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

  • 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);
    }

  • Problem extending JPanel

    Hi,
    What is the best format to have a class with a JFrame and a number of JPanels, one of which needs to be painted on using Graphics.
    class Demo extends JPanel{
    public JFrame frame;
    public JPanel panel1;
    public JPanel panel2;
    public JPanel panel3;
       Demo(){
          // initialise JFrame
          frame = new JFrame();
          // initialise a few JPanels
          panel1 = new JPanel();
          panel2 = new JPanel();
          panel3 = new JPanel();
          // refer to the JPanel I'm painting on
          frame.getContentPane(this);   // Is this correct?
         public void paint(Graphics g)     {
              g.drawString("Click below", 50, 50);               
                  // now this method should paint over one of the JPanels only, the one I'm extending..
    }Any thought appreciated.

    Thanks for the pointers Haynese ,
    I understand what I should be doing.
    I have another issue with this now, maybe its constructed badly...
    I can get the graphics objects on the JPanel to display but not the JButton or label I add. If I click in the region of the button and hit it, it appears. Any ideas?
    public class GraphEditor extends JPanel implements MouseListener
    public JButton button;
    public JLabel label5;
         public GraphEditor(){
              //  JPanel Button, displays if clicked on.
              button = new JButton("JPanel Button, displays if clicked on...");
              this.add(button);
                                             //  This should display but never does
              label5 = new JLabel("This should display but never does");
              add(label5);
              setSize(50,50);
              setVisible(true);
         public void paint(Graphics g)     {
                                            // This displays fine
              g.drawString("This displays fine", 5, 5);               
    }and:
    public class SystemWindow extends JFrame {     
    public JButton button;
    public JPanel topPanel;
    public JPanel bottomPanel;
    public JPanel mainPanel;
    public JLabel topPanelLabel;
    public JLabel bottomPanelLabel;
    public JButton getPathButton;
    private GraphEditor mainMap = new GraphEditor(this);
         SystemWindow(){     
             topPanel = new JPanel();
              bottomPanel = new JPanel();
              mainPanel = new JPanel();
              // 10 is horizontal
                                               // 01 is vertical
              getContentPane().setLayout(new GridLayout(0,1));
              getContentPane().add(mainPanel);
              mainPanel.add(topPanel);
              mainPanel.add(bottomPanel);
              topPanelLabel = new JLabel("Top Panel");
              topPanel.add(topPanelLabel);
              bottomPanelLabel = new JLabel("Bottom Panel");
              bottomPanel.add(bottomPanelLabel);
              button = new JButton("Save");
              //button.addActionListener(this);
              bottomPanel.add(button);
              getPathButton = new JButton("Get");
              //getPathButton.addActionListener(this);
              bottomPanel.add(getPathButton);
              getContentPane().add(mainMap);
              setTitle("App Title");          
              setSize(500,300);          
              setLocation(100,100);     
              mainPanel.setVisible(true);
              topPanel.setVisible(true);
             bottomPanel.setVisible(true);
             setVisible(true);
         }          Any suggestions welcome.

  • Extending JPanel bug?

    Hi,
    I have built a custom panel by extending JPanel. I have then set the layout of my custom panel to BorderLayout, and added 2 more panels: one in the center, one in the west. The one on the west has a button on it, the one in the center is empty, so that sub classes can add their own widgets to it. Whenever I create a new instance of either this panel or one of the sub classes I have created, and add it to another JPanel (with layout set to null), it only displays the custom panel and the background and border of it: it does not display the other panels that I have added to it. However when you resize the frame which holds the GUI (by clicking and dragging it at the edges), it displays the custom panel correctly.
    I am calling repaint method after adding the custom panel to the other one (the one with layout set to null). Is this display a bug in Java? If so, is their a way round it? Or is my code wrong?
    Thanks in advance for any advice.
    silverwatch.

    Yes layouting is often a headache.
    In general one adds components and calls pack in the JFrame to layout things. It seems you must call validate (invalidate?) before your repaint. A repaint(ms_delay) might be in order, if you are "in the message loop."

  • Access Privileges Button does not bring up pop-up Menu -- SOLUTION

    Hi. I was puzzling for a long time over why my Access Privileges Button did not work under System Preferences // Sharing on the Apple Remote Desktop Panel. I tried re-installing the Remote Desktop Bundle, removing System caches and so forth but nothing fixed it.
    The culprit was that somehow the following support file was missing: RemoteDesktop.bundle inside of the following directory: /System/Library/PreferencePanes/SharingPref.prefPane/Contents/Resources .
    I copied the file from another MacBook by selecting System/Library/PreferencePanes/SharingPref.prefPane in the Finder and then using the option menu to select Show Package Contents.
    I hope this will help anyone else who has run across this problems. Thanks.

    Thankyou VonHamhorse. I was met with the same problem.. EXACTLY. Your solution worked. My situation involved two Intel iMacs. Pre-sharing pane problems, I deleted the extra user from the iMac in question. (I was having to enter in an admin name and password everytime I upgraded the software. I found by deleting the second user that was installed by an ARD Admin package, I no longer had to enter in two sets of confirmations for each time I upgraded software.) However, after that deletion, I no longer could access the iMac via ARD Admin. I was working on that iMac tonight and decided to check out the "Sharing Control Panel" when I discovered I had no drop down menu. A quick search in discussions brought up your solution and in minutes, I had control again! Hopefully I'll be able to rectify my connection now.. Thanks again.

  • Restrict access to buttons, regions, etc. on a per user basis?

    My application restricts access to buttons, regions, etc. on a per user basis.
    Here is my application logic...
    1. A User can only edit items they own.
    2. A Super-User can edit all items
    So, when a user logs in, I use a post-authentication process to set the user ID to an application level item.
    Now, for example, to have an edit button display on a page, I need to check the item's owner ID against the application level user ID...and check to see if this user is on the Super User list via a query.(which could be set to another application level item upon login...I guess)
    Question...What is the best way to do this? Conditional display? Authorization scheme?
    Would something like the following work for a Conditional Display?
    Condition: SQL Expression
    &USER_ID.=&P6_ITEM_OWNER_ID. OR USER_ID in (select USER_ID from table where USER_ID=&USER_ID.)
    How would I do this with an Authorization Scheme? (I like the idea of updating the logic in single location...but I'm not sure if it is possible because I have to check PX_OWNER_ID would be different on each page.)

    Hi Denes,
    Thanks for your code which allows user to edit (if authorized) and view (if not).
    But some how - I do not get the image to show up - instead it show a small underline.
    From SQL point of view - here is what I get - when i run the sql
    '<img src="/i/ed-item.gif">',2,CR TEST,,,,dune2.cit.cornell.edu,CRDMTEST.CIT.CORNELL.EDU,PSPROD,,,CRDMTEST
    Here is my wrap_image function
    create or replace function wrap_image(p_user_name in varchar2,p_dm_name_id in number)
    return varchar2 IS
    v boolean := False;
    ret_val varchar2(1000);
    begin
    dbms_output.put_line('user='||p_user_name);
    dbms_output.put_line('dm_name='||p_dm_name_id);
    -- Check authorization if the user is super user - return true, else if he has edit priv on dm_name_id - return true - else false
    v:=ACL_DMTOOLS_DM_PRIV(p_user_name,p_dm_name_id);
    if v then
    ret_val := '<img src="/i/ed-item.gif">';
    ret_val := ''''||ret_val||'''';
    dbms_output.put_line('TRUE');
    else
    ret_val := '';
    dbms_output.put_line('FALSE');
    end if;
    return ret_val;
    end;
    Thanks for your great educational site.
    Regards
    atul

  • Access multiple buttons in a loop??

    Hi,
    This is a continuation of my last question and I am hoping Ned will tell my what to do. I am really thankful for all your help so far...:) The problem now is that I need to access the buttons in the following format.
    img1._alpha = 100;
    I tried the following within the loop,
    ["img" + i]._alpha
    "img" + i._alpha
    both are incorrect. Can you please tell me how I can attach the i to img, so that I can call it within a loop??

    the brackets need a lead in object, so if there is no containing object (like an mc), "this" usually works... though you could also probably use _root (avoid using _root unnecessarily/habitually though)
    this["img" + i]._alpha

  • 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"));

  • 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

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

  • 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());}

Maybe you are looking for

  • How can I unmark photos which are marked for republish to Flickr?

    I am currently using Lightroom 3 to publish photos to Flickr. I have a free Flickr account. My problem is that I have a set of photos I am publishing to flickr. For some reason some of my photos lost their keywords, only the files on my computer lost

  • Problem when inserting Spry Tabbed Panels

    Hi all, Just lately i started to get this message when inserting spry tabs " ! The structure of this widget appears to be damaged. Go to Code view and repair the widget, or replace the widget." Anyone know why and how to fix it? At first i thought it

  • BCALV_EDIT_03 - Need the table update function

    I am fairly new to OO programming and have worked through the various sample programs. I am currently using BCALV_EDIT_03 and _04 to write a table maintenance program. I kind of have figured out how the delete and insert function works but unfortunat

  • PIAC Status and Physical inventory history

    Hi Experts, When Issuing goods / Posting material docs following error message is displayed. "Serial Number XXXXX cannot be used - System status PIAC is active (EQU XXXXX)u201D 1. When cross checked with the relevant Inventory document, i could not f

  • Where Is the Label Tag

    I am looking at the IPTC and EXIF data of pictures managed in Lightroom. I can't find the tag that stores the Label (the different color codes) information. I did a "Save Metadata to File" so it should be there. FYI, Expression Media stores it in the