Flickering problem in JPanel

hello, i'm sorry this might be a too popular topic, but my problem is a little different.
I have a JPanel which is newed with an Image, and I move it (using setBounds()) in my application when a button is clicked. It flicked badly ... after I've done some research, then i use the setDoubleBuffered(true), still the same problem, isn't the API used to remove the flickering by doubled buffering? I'm using JDK 1.3.1, FYI.
could anyone throw me some lights on this? greatly appreciate it ..
Steve

Thanks for the prompt reply, i extract those code related ... sorry I was wrong in my previous post that this is a JLabel, not a JPanel.
The logic is pretty easy, everytime a button is clicked, I draw a JLabel at a different positioin (we also need to new it with an ImageIcon if it's the first time), that's it. but the problem is it flickered badly, and setDoubleBuffered(true) doesn't solve this problem as I expect.
Thanks for any comment.
public class MainView extends JLayeredPane
public void actionPerformed(ActionEvent e) {  // when a button is clicked     
if (first) { // if this is the first time, do the JLabel initialization
bottomPicLabel = new JLabel(bottomViewImage.getImage());
bottomPicLabel.setDoubleBuffered(true);
add(bottomPicLabel, BOTTOM_LAYER);
int bottomWidth = bottomViewImage.getEndX() - bottomViewImage.getStartX();
int bottomHeight = bottomViewImage.getEndY() - bottomViewImage.getStartY();
     // draw at a different place
bottomPicLabel.setBounds(
bottomViewImage.getStartX(),
bottomViewImage.getStartY(),
bottomWidth,
bottomHeight
}

Similar Messages

  • Problem with Jpanel repaintingl

    Hi!
    I have a problem with Jpanel.
    First , I add a Jscrollpane to the panel and I don't
    see it.
    Second, I have a paint method in the Jpanel and I do there some painting but when I exe the application I can see the panel painting only when I put the mouse cursor
    on the place where the panel need to be.
    It is very strange.
    Help me.
    Yair.

    Example code??
    Can't tell what's wrong otherwise.
    First , I add a Jscrollpane to the panel and I don't
    see it.Have you added anything to this JScrollPane? Unless you set the scroll bar policies to always on you won't see anything if you haven't added anything to the scrollpane.
    Also, if you're only adding this scrollPane to your JPanel initilise it with
    JPanel whippet = new JPanel(new BorderLayout())
    .. then when you add your scrollPanel to your JPanel do this to make sure its added slap in the in middle of it:
    whippet.add(yourScrollPanel, BorderLayout.CENTER);
    Bit more info please - duuuuuuuuuuuuuuuude (man, "Finding Nemo" was well funny didn't you think.. anyways, that's besides the point.... could just be my 8 year old mental age though.. who knows.)?

  • Facing "Display Flickering" problem with my 15" macbook pro(A1286)while swapping the desktops and closing the tabs.....need help...reply soon

    Suggest Solution for this Display Flickering problem ....

    Hi, I read the post about calibration and I probably do that a little too often TBH! As I get so little time out the battery and mainly use my MBP on my lap, usually with the power supply near by, it gets charged to full, run to empty to the point of sleep, or sometimes it even cuts out and then is recharged to full again, so I really think it's new battery time. I've seen non Apple Official ones for between £35 and £65 that have 3 year warranties and state they are around 5200mh but am unsure due to reviews.
    Later...
    Anyway's I have now ordered a non Apple replacement from Amazon for about £35 and it has several good reviews and 4.5 out of 5 stars so I'll see if it works and report back. If it doesn't I'll send it back and get the Official Apple one.
    Message was edited by: Missy Steph

  • MDIChildren flickering problem while switching between child form with dockstyle.fill and borderstyle.none

    I have an mdi applicaton in Visual studio 2010 (.Net framework 4.0). I'm having a flickering problem when user switch between an MDI Child form. I'm declaring the child form then setting the borderstyle.none at design time and dock property to fill
    through programming and make them a MDIChildren before I show them so that it takes up the entire space of the MDI Parent window without being maximized (client request). 
    i don't want to display control box(minimize, maximize,close) of child form in mdi parent form. (client request)
    The problem is that when the child form is being displayed it is briefly shown in it's default size with icon and control box before being resized to fill the available area on the MDI Parent form. When a Child Form loads, you can see it in it's original
    size (the size from Design-time) then all this flickering while maximizing .
    In other words, child form show up in the client area of the MDIForm, not maximized, with a caption, very shortly, before they are finally filling the client area. there is a short flicker when a new form is created and displayed. This process is most noticeable
    with a not-so-powerful PC or there are lots of control inside child form.
    below is my code to show child form 
       MyChild1 c1 = new MyChild1();
                                c1.MdiParent = MdiMainParent;
                                c1.Dock = DockStyle.Fill;
       c1.Show(); 
    how can i solved the problem of flickering issue?
    I tried many options which i have described below
    1.double buffering.
    2.set style property to child form
          this.SetStyle(ControlStyles.UserPaint, true);
          this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
          this.SetStyle(ControlStyles.DoubleBuffer, true); 
    3. override below method in each child form
    protected override CreateParams CreateParams
                get
                    CreateParams cp = base.CreateParams;
                    cp.ExStyle |= 0x02000000;
                    return cp;
    4. override below method in each child form
      const int WM_NCPAINT = 0x85;
            const int WM_SIZE = 0x05;
            protected override void WndProc(ref Message m)
                if (m.Msg == WM_NCPAINT)
                    if (this.WindowState == FormWindowState.Maximized)
                        return;
                if (m.Msg == WM_SIZE)
                    if (this.WindowState == FormWindowState.Maximized)
                        return;
                base.WndProc(ref m);
    but I didn't see any effects.  please someone help me to resolve flickering issue. thanks in advance.

    Hi hardikvaishnav,
    This is a known issue which has been reported to Microsoft Connect. Unfortunately, this issue will not fix due to stability issues around MDI. For more details, see 
    https://connect.microsoft.com/VisualStudio/feedback/details/97787/border-of-mdi-child-form-flashes-up-despite-formborderstyle-none.
    You might use a user control or panel instead.
    Best Regards,
    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

  • ALV flickering problem

    Hi,
    I have  flickering problem with ALV control (cl_gui_alv_grid).  My alv grid  control is not in edit mode.
    I am using ALV grid for event planning with drag drop operations, so there may be 1000+ rows sometimes at grid.
    Also I call refresh_table_display with soft_refresh and is_stable='XX.'
    (I call cfw=>set_new_ok_code to trigger PBO. refresh_table_display is being called at PBO )
    It flickers just a second or two after drop_complete but it is critical for usability.
    I think flickering happens because of scrolling, so I used set_scroll_via_id but nothing changed.
    Thanks.

    Hi Manu,
    I tried not to trigger PBO (Called refresh_table_display at PAI, commented set_new_ok_code)
    It does not help..
    (Same behaviour : se38-> BC_ALV_TEST_GRID_PERFORMANCE.Increase record count to 5000.Run.
    Scroll to the bottom of list.)
    Thank you..

  • Flickering problem with Apple TV

    I am suddenly having flickering problems after updating Apple TV.  The box has worked fine for several months though I did have this same problem when I first got it in February.  I have a Panasonic 37' viera.  I have unplugged both the TV and the Apple TV box, reset it a number of times.  Don't know what to do.

    I'm having the same issue, albeit right out of the box.  I hooked up my Apple TV according to the instructions, have no other issues with my wifi, and the HDMI and power cables are all securely connected.  My TV's also a Samsung, experiecing the same "flickering" of audio.  In addition, during set-up, the screen was also flickering to white while inputting my wifi info.
    Am hoping swapping it out in store will fix the problem. I was so excited to get my AppleTV in the mail and everything else Apple-to-TV has been working great. (I had my ancient black MacBook -turning 6 in June- hooked up with zero connectivity problems.)  Wondering if this will be an ongiong issue? Had decided against AppleCare for such an inexpensive addition to my home, but maybe I should re-think that decision...

  • Flickering problem with live viewing with IMAQ Image Display

    Hi everyone,
    I am trying to write a program to do live imaging with Andor camera. I am using some examples from Andor. The images are acquired in sequence and send into IMAQ Image Display and also Intensity Graph. There is minimal flickering issue in the Intensity Graph but there is very bad flickering problem in IMAQ Image Display. Perhaps I misunderstand how to optimize the vision tools. Does anyone know how to overcome this issue? I have attached the code that I am testing. Thanks in advance.
    Best regards,
    Han Yen
    Solved!
    Go to Solution.
    Attachments:
    iXonRTA_live_0.0.1.vi ‏70 KB

    You can use Vision Assistant to test our vision functions. Vision Assistant is really meant to prototype - it does not have all teh functionality of Vision Development Module and is not as flexible as we don't allow you access to all the settings for every function.
    I recommend starting in Vision Assistant and then porting over to LabVIEW or C (whatever you are most comfortable with)...this is built-in functionality. There is nothing wrong with using Vision Assistant to do live imaging, just that you run into limitations and you will only be able to use this code on computers that have Vision Assistant.
    Hope this helps.
    --Michelle
    Instrument Control R&D
    National Instruments
    Instrument Control
    Machine Vision

  • Flickering problem on screen - 3000 series N200 laptop

    Hello!
    I have a 3000 series N200 laptop (0769 type) for 3 years. Approximately 3 months ago, there was a screen problem that the screen had white vertical gridlines. Service replaced the chipset of the graphical card.
    Yesterday, a flickering problem has been appeared. I updated bios and display drivers from below link.
    http://support.lenovo.com/en_US/downloads/default.page?
    Could not get a solve with those updates. Then, I dismounted the front cover of screen. Re-assembled the LVDS FFC cable of the LCD display a couple of times, problem continued. Then, re-assembled the inverter cables. It also did not provide a solution.
    >See the problem photo (1.jpg) at below link.
    https://docs.google.com/open?id=0BweTh37k3ZRSQWYxRFNIWWpGSFE
    Please advise about this matter.
    Thanks.

    Hello suguz and welcome to community,
    As you have already updated the video driver and BIOS then you can check with adjusting the monitor refresh rate to 60Hrz.
    Kindly check the same issue in BIOS mode and if issue continues then it might fault with Lcd display.
    Best Regards,
    Tanuj
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution".! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
    Follow @LenovoForums on Twitter!

  • MSI R9 270X Twin Frozr flickering problem

    Hey guys. I have a MSI R9 270X Twin Frozr and i'm having the flickering problems, mentioned already here in several topics.
    I'm using Windows 7 64 and  AMD Catalyst 13.11 Beta9.5 Driver.
    The S/N of my card is: 602-V303-03SB1310018161
    I really need your help. Thanks in advance

    Quote from: flobelix on 26-December-13, 01:54:04
    It's totally easy and welll documented. You'll need the win98boot file to point the tool to or it can't create a dos boot stick.
    flobelix can u tell me which version is my vbios?
    MSI R9 270x Twin (BIOS 015.041) SN: 602-V303-03SB1310017043
    I've flashed it already with 303MS.102 and still get Black Screen when installing drivers! Do you guys have any new info about it? I can't do anything with it.

  • Problem with JPanel and/or Thread

    Hello all,
    I have the following problem.
    I have a JFrame containing to JPanels. The JPanels are placed
    via BorderLayout.
    JPanel #1 is for moving a little rectangle (setDoubleBufferd), it is
    a self defined object extending JPanel.
    The paint methon in JPanel #1 has been overwritten to do the drawings.
    JPanel #2 contains 4 JButtons, but they have no effect at the
    moment. It is an "original" JPanel.
    The class extending JFrame implemented the interface Runnable and
    is started in its own thread.
    After starting the programm everthing looks fine.
    But if I press a Button in the second JPanel this button is painted in
    the top left corner of my frame. It changes if I press another button.
    Any help would be appreciated.
    Thanks.
    Ralf

    I have a JFrame containing to JPanels. The JPanels are
    placed
    via BorderLayout.The type of Layout does not seem to be relevant
    >
    JPanel #1 is for moving a little rectangle
    (setDoubleBufferd), it is
    a self defined object extending JPanel.
    The paint methon in JPanel #1 has been overwritten to
    do the drawings.
    JPanel #2 contains 4 JButtons, but they have no effect
    at the
    moment. It is an "original" JPanel.
    The class extending JFrame implemented the interface
    Runnable and
    is started in its own thread.
    After starting the programm everthing looks fine.
    But if I press a Button in the second JPanel this
    button is painted in
    the top left corner of my frame. It changes if I press
    another button.
    I noticed you solved this by painting the whole JFrame.
    Yeh Form time to time I get this problem too......
    Especially if the screen has gone blank - by going and having a cup of tea etc -
    Text from one Panel would be drawn in another.. annoying
    At first it was because I changed the state of some Swing Components
    not from the Event Thread.
    So make sure that your new Thread doesn't just blithely call repaint() or such like cos that leads to problems
    but rather something like
    SwingUtilities.invokeLater( new Runnable()
       public void run()
          MyComponent.repaint();
    });However I still get this problem using JScrollPanes, and was able to fix it by using the slower backing store method for the JScrollPane
    I could not see from my code how something on one JPanel can get drawn on another JPanel but it was happening.
    Anyone who could totally enlighten me on this?

  • Problem with JPanel in JFrame

    hai ashrivastava..
    thank u for sending this one..now i got some more problems with that screen .. actually i am added one JPanel to JFrame with BorderLayout at south..the problem is when i am drawing diagram..the part of diagram bellow JPanel is now not visible...and one more problem is ,after adding 6 ro 7 buttons remaing buttons are not vissible..how to increase the size of that JPanel...to add that JPanel i used bellow code
    JFrame f = new JFrame();
    JPanel panel = new JPanel();
    f.getContentPane().add(BorderLayout.SOUTH, panel);

    Hi
    JFrame f = new JFrame();
    JPanel panel = new JPanel();
    // Add this line to ur code with ur requiredWidth and requiredHeight
    panel.setPreferredSize(new Dimension(requiredWidth,requiredHeight));
    f.getContentPane().add(BorderLayout.SOUTH, panel);
    This should solve ur problem
    Ashish

  • Problem with JPanel, JMenuBar

    Hi, I'm new here so I'm not even sure if I'm posting in the correct forum ^^
    I usually don't have problems when building a JFrame and adding items into it but now I'm confused.
    When the JFrame is "built", I get a NullPointerException from the Panel's paintComponent method when it's trying to draw an image (g.drawImage())
    This is the whole JPanel class
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class PanneauDe extends JPanel
      private static final String [] TAB_IMAGE = { "De1.GIF", "De2.GIF", "De3.GIF",
                                                   "De4.GIF", "De5.GIF", "De6.GIF" };
      private static final int [] TAB_FREQUENCE = {0,0,0,0,0,0};
      private static final int SIDE = 100;
      private De unDe;
      private ImageIcon imageDe;
      private boolean aFirstTime;
      private int aX, aY; 
      public PanneauDe()
        unDe = new De();
        aX = aY = 0;
        aFirstTime = true;  
        addMouseListener(new EcouteurSouris());   
      public String getStats()
        String statsMsg = "";
        for ( int iPos = 0; iPos < TAB_FREQUENCE.length; iPos ++ )
          statsMsg += "Face " + (iPos + 1) + " : " + TAB_FREQUENCE[iPos] + " fois\n\n";
        return statsMsg;
      public String getTotal()
        int total = 0;
        for ( int iPos = 0; iPos < TAB_FREQUENCE.length; iPos ++ )
          total += TAB_FREQUENCE[iPos];
        return "Le d� a �t� lanc� " + total + " fois";
      public void throwDice()
        unDe.throwAgain();
        TAB_FREQUENCE[unDe.getFace() - 1] ++;   
      public void paintComponent (Graphics g) 
        super.paintComponent(g);
        g.drawImage (imageDe.getImage(), aX, aY, null); // <---- THIS GENERATES THE NULLPOINTEREXCEPTION
      class EcouteurSouris extends MouseAdapter
        public void mouseClicked (MouseEvent pMouseEvent)
          aX = pMouseEvent.getX();
          aY = pMouseEvent.getY();
          throwDice();
          imageDe = new ImageIcon(TAB_IMAGE[unDe.getFace() - 1]);
          repaint();
    }When I click in the windows, a picture of a dice (different side, randomly generated by the method throwDice() ), when I click again the first image dissapear and another one appears... and I make statistics about the results.
    I tried ...
      public void paintComponent (Graphics g) 
        super.paintComponent(g);
        //g.drawImage (imageDe.getImage(), aX, aY, null);
      class EcouteurSouris extends MouseAdapter
        public void mouseClicked (MouseEvent pMouseEvent)
          aX = pMouseEvent.getX();
          aY = pMouseEvent.getY();
          throwDice();
          imageDe = new ImageIcon(TAB_IMAGE[unDe.getFace() - 1]);
          Graphics g = getGraphics();
          g.drawImage (imageDe.getImage(), aX, aY, null);
          g.dispose();
        }Everything works correctly, no more NullPointerException, but the images don't dissapear when I click again. They just stay there.
    I'm not completly familiar with the repaint/dispose/paintComponent but I really don't understand why i get this NullPointerException error :\
    If you see some weird words in the code, it's because i'm canadian-frenchy! :)
    Full program is here

    The real question is why are you trying to override the paintComponent() method. Just add the image to a JLabel and add the label to a panel.
    However, the problem is that the paintComponent() method is invoked when the frame is shown and since you don't create the image until you do a mouseClick, the image in null.

  • Problem with jpanel size

    Hi I want to add a view port to a JPanel
    the main problem is that the Jpanel change size as the frame.
    how can i make it independent from the frame so having it; own w, h
    thanks
    package help;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import javax.swing.*;
    public abstract class MyFrame extends JFrame {
    private static final long serialVersionUID = 1L;
    private static JButton drawCircle, drawRectangle, drawSquare, drawStar, start, clear,quit,back, screenshoot;
    static final int FPS_MIN = 0;
    static final int FPS_MAX = 150;
    static final int FPS_INIT = 0;
    static int fps;
    double x1,x2;
    double y1,y2;
    int dr =1;
    int dy= 1;
    int Selection=0;
    boolean click=true; //check if start has been clicked
    int width = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;  // screen width
    int height = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;     //screen higth
    protected static int count;
    int R,G,B;  //color
    Cursor c;                    //cursor object
    private static ShapePanel bpnl;
    public MyFrame()
            R=G=B=0;
            int width = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
            int height = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height-100;
            JFrame frame=new JFrame();
            BorderLayout layout=new BorderLayout();
            frame.setLayout(layout);
            frame.setTitle("Game");
            //panel to hold buttons
            JPanel upPanel = new JPanel();
            upPanel.setLayout(new FlowLayout());
            upPanel.setSize(width, height/5);
            //panel to hold SLIDERS
            JPanel leftPanel = new JPanel();
            leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
            leftPanel.setSize(50, height);
            //initialize buttons and add to the upPanel
            drawCircle=new JButton("Draw Circle");
            upPanel.add(drawCircle);
            drawStar=new JButton("Draw Star");
            upPanel.add(drawStar);
            drawRectangle=new JButton("Draw Rectangle");
            upPanel.add(drawRectangle);
            drawSquare=new JButton("Draw Square");
            upPanel.add(drawSquare);
            start=new JButton("Start");
            start.setBackground(Color.GREEN);
            //upPanel.add(start);
            clear=new JButton("Clear");
            upPanel.add(clear);
            back=new JButton("Back");
            upPanel.add(back);
            quit=new JButton("Quit");
            quit.setBackground(Color.red);
            upPanel.add(quit);  
            screenshoot=new JButton("ScreenShoot");
            c = new Cursor (Cursor.CROSSHAIR_CURSOR);     //Change cursor to cross hair
         this.setCursor (c);
            //new object spanel to hold TIMER
            JPanel spanel=new JPanel();
                spanel.setLayout(new GridLayout());
                //slider dimension construction
                JSlider sDimension = new JSlider(JSlider.HORIZONTAL,FPS_MIN, FPS_MAX, FPS_INIT);
                sDimension.setMajorTickSpacing(30);
                sDimension.setMinorTickSpacing(3);
                sDimension.setPaintTicks(true);
                sDimension.setPaintLabels(true);
                Font font = new Font("Serif", Font.ITALIC, 15);
                sDimension.setFont(font);
                sDimension.setBorder(BorderFactory.createTitledBorder("Shape Dimension"));
                //slider speed construction
                int FPS_MIN_s = 0;
                int FPS_MAX_s = 60;
                int FPS_INIT_s = 0;    //initial frames per second
                JSlider sSpeed = new JSlider(JSlider.HORIZONTAL,FPS_MIN_s, FPS_MAX_s, FPS_INIT_s);
                sSpeed.setBorder(BorderFactory.createTitledBorder("Shape Speed"));
             ////////////////////////// // slider colors////////////////////////////////////////////////////
                int FPS_MIN_C = 0;
                int FPS_MAX_C = 250;
                int FPS_INIT_C = 0;  
                JSlider sliderR= new JSlider(JSlider.HORIZONTAL,FPS_MIN_C, FPS_MAX_C, FPS_INIT_C);
                sliderR.setBorder(BorderFactory.createTitledBorder("Red Channel"));
                JSlider sliderG= new JSlider(JSlider.HORIZONTAL,FPS_MIN_C, FPS_MAX_C, FPS_INIT_C);
                sliderG.setMajorTickSpacing(50);
                sliderG.setMinorTickSpacing(25);
                sliderG.setPaintTicks(true);
                sliderG.setPaintLabels(true);
                sliderG.setFont(font);
                sliderG.setBorder(BorderFactory.createTitledBorder("Green Channel"));
                JSlider sliderB= new JSlider(JSlider.HORIZONTAL,FPS_MIN_C, FPS_MAX_C, FPS_INIT_C);
                sliderB.setBorder(BorderFactory.createTitledBorder("Blue Channel"));
              //     spanel.add(sSpeed,BorderLayout.EAST);
                  frame.add(upPanel,BorderLayout.NORTH);
                  frame.add(leftPanel,BorderLayout.WEST);
                  bpnl = new ShapePanel(3000,3000);
                        System.out.println("panel width = "+bpnl.getWidth() +"  heigth = " + bpnl.getHeight());
                        bpnl.setFocusable(true);
                  upPanel.setBackground(Color.DARK_GRAY);
                  upPanel.setBorder(BorderFactory.createLineBorder(Color.white));
            frame.add(spanel,BorderLayout.SOUTH);       
            frame.add(bpnl, BorderLayout.CENTER);
            frame.setSize(width, height);
            frame.setVisible(true);               
               leftPanel.add(sliderR);
               leftPanel.add(sliderB);
               leftPanel.add(sliderG);
               leftPanel.add(sDimension,BorderLayout.WEST); 
                 System.out.println("panel width = "+bpnl.getWidth() +"  heigth = " + bpnl.getHeight());
              public static  int getPanelWidth()
                  System.out.println("panel width   "+bpnl.getWidth());
                  return bpnl.getWidth();
              public static  int getPanelHeigth()
                  System.out.println("Panel heigth  " +bpnl.getHeight());
                  return bpnl.getHeight();
              public static void main(String args[])
                  new MyFrame() {};
    package help;
    import java.awt.Cursor;
    import java.awt.Graphics;
    import javax.swing.JPanel;
    class ShapePanel extends JPanel  {
         private static final long serialVersionUID = 1L;
         private javax.swing.Timer animationTmr;
         private float heigth;
         private float width;
         private Cursor c;
         public ShapePanel(int w, int h) {
                    int W=w;
                    int H=h;
                    c = new Cursor (Cursor.CROSSHAIR_CURSOR);     //Change cursor to cross hair
                    this.setCursor (c); 
                    this.setPreferredSize(3000,3000);
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              g.fillRect(0, 0, this.getWidth(), this.getHeight());
        private void setPreferredSize(int i, int i0) {
        thanks

    sorry i hope this is better
    package help;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public abstract class MyFrame extends JFrame {
    private static final long serialVersionUID = 1L;
    int dr =1;
    int dy= 1;
    int Selection=0;
    int width = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;  // screen width
    int height = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height-100;     //screen higth
    private static ShapePanel bpnl;
    public MyFrame()
            JFrame frame=new JFrame();
            BorderLayout layout=new BorderLayout();
            frame.setLayout(layout);
            bpnl = new ShapePanel(3000,3000);
            System.out.println("panel width = "+bpnl.getWidth() +"  heigth = " + bpnl.getHeight());
            bpnl.setFocusable(true);
              frame.add(bpnl);
            frame.setSize(width, height);
               pack();
            frame.setVisible(true);               
    System.out.println("panel width = "+bpnl.getWidth() +"  heigth = " + bpnl.getHeight());
              public static  int getPanelWidth()
                  System.out.println("panel width   "+bpnl.getWidth());
                  return bpnl.getWidth();
              public static  int getPanelHeigth()
                  System.out.println("Panel heigth  " +bpnl.getHeight());
                  return bpnl.getHeight();
              public static void main(String args[])
                  new MyFrame() {};
    package help;
    import java.awt.Cursor;
    import java.awt.Graphics;
    import javax.swing.JPanel;
    class ShapePanel extends JPanel  {
         private static final long serialVersionUID = 1L;
         private Cursor c;
         public ShapePanel(int w, int h) {
                    int W=w;
                    int H=h;
                    c = new Cursor (Cursor.CROSSHAIR_CURSOR);     //Change cursor to cross hair
                    this.setCursor (c); 
                    this.setPreferredSize(3000,3000);
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              g.fillRect(0, 0, this.getWidth(), this.getHeight());
        private void setPreferredSize(int i, int i0) {
       

  • Problem with JPanel in a JScrollPane

    Hi all,
    I am devloping an application where in i insert the JPanel's object in the JScrollPane object. Intitially the size of the JPanel's object is more than the size of the JScrollPane object.At this point fo time i can drag the nob of the scrollpane to the extent of the size of the JPanel's object. Now When i move the mouse behond the size of the JPanel i am increasing the size of the JPanel's object but i cant move the nob of the scrollpane object behond the original limit.
    For example : when you open a notepad there will be scrollbar without the nob if you keep on pressing the enter key the size of the text area increases and we can see the scroll bar now. I what the similar functionality but
    instead of TextArea i need the panel.
    If any of you have solved this problem or know the solution please do inform. I need to solve this problem very urgently. Please do help me out.
    Thanks in Advance.
    regards
    Ravi

    Hi all,
    I got the solution.we need to revalidate the panel object.
    i.e JPanel.revalidate()
    regards
    Ravi Kumar

  • Problem with JPanel after rotation

    Hi,
    I am developing a graphics editor like mspaint. I have JPanel as my drawing canvas. now the problem is when I rotate the canvas, co-ordinates on the canvas are also getting rotate with it. for example if top-left corner is (0,0) initially then after rotating it 90 degree top-right corner becomes (0,0) and same for all the points on the canvas.
    the code i m using for rotation is
    contentPanel = new JPanel(){
    @Override
    protected void paintComponent(Graphics g) {                       
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    Rectangle rect=g2.getClipBounds();
    if(rotation!=0){
    double angle = rotation * Math.PI/2;
    g2.rotate(angle,getWidth()/2,getHeight()/2);
    rect=g2.getClipBounds();
    setPreferredSize(new Dimension(rect.width,rect.height));
    super.paintComponent(g);
    revalidate();
    };

    Whats your question?
    If you rotate it, of course the points will rotate, they have to.

Maybe you are looking for

  • Random jobs stopping print queue

    I have 3 printers attached to my iMac via a USB hub, a canon i9100, an epson SP 220 and an epson SP 1800. I have experienced this with all of the printers, so I don't believe it is a problem with the printer software. Most of the time everything work

  • Poor Safari Performance - not crashing though

    The spinning beachball appears (no clues as to triggers) Safari is then unresponsive If I activate another app (eg click on the desktop to activate finder, call up 'force quit' etc), Safari starts working again Have uninstalled plugins (glims); still

  • Shared Services database content not found in the specified database."

    Trying to configure Version 11 and get the error: "Shared Services database content not found in the specified database". Relevant details on my issue as below: - I'm running Windows 7 and SQL Server 2008 on my local machine. - I did have a previous

  • Data Dictionery Overview

    Hello Experts-- M new into the SAP field, nd also i have heard thtfor  making a good carrier in SAP,  strong hold on Data Dictionery is must, so can you experts lettme know what exactly should be my flow to get all the concepts of DD and its heirarch

  • Xml parsers supported by JAXP1.1

    I'd like to know the xml parsers and their versions supported by JAXP1.1. although crimson.jar is the default parser provided, but i want to use a different parser. I need the answers urgently, Thanks.