Avoiding the repaint of all components in an JApplet

Hello everyone,
Thannks to all who gave me advices for the two JComboBoxes I had...finally I found two "if" conditions in the actionPerformed of the first JComboo which restricted the list of elements posted in the second one.
I have a much bigger problem now....The Applet contains an object which is an extension of JPanel, and in this extension there is a "paintComponent()" that creates a certain number of JButtons in a "for" loop. The problem I have is :
How could I avoid this panel to be repainted every time the page containing the Applet is resized? Is it even possible( because from what I've been reading a "paint()" of the applet always calls for all the components' "repaint()".....I haven't even definned a "paint()" for the applet, .....and then, each button has an action listener that simply won't work after a repaint() of the whole applet. And honestly i'm starting to lose my mind a bit over all this......Oh, I had almost forgotten....the problem after re-sizing is that within the borders of the Panel there are always buttons created by the "for" loop ....and they are smaller and appear high up "north" in the panel...it's horrible!!!!!
This is my code for the paintComponent() of the extension of the JPanel:
public void paintComponent(Graphics g){
       g.drawLine (130,50,130,450);
       g.drawLine (129,50,129,450);
       g.drawLine (270,50,270,450);
       g.drawLine (271,50,271,450);
       g.drawString("Plateau no.", 80,40);
       g.setColor(ballon);
       g.fillArc(100,434,200,100,45,-270);
       System.out.println("I've been through paint");
    for(int i=0;i<13;i++)
       System.out.println("buton ok"+i);
       plateaux=new JButton();
plateaux[i].setEnabled(true);
plateaux[i].addActionListener(this);
Color cri=new Color(240-15*i,0,0);
plateaux[i].setBounds(130,60+30*i,139,15);
plateaux[i].setBackground(cri);
add(plateaux[i], null);
g.drawString(" "+ (13-i),105,70+30*i);
There's nothing else in the extension....only the paint ...it implements ActionListener.....
Thankx in advance....I'd really apreciate it if someone could help me.....
Ruxi

To clear the background for each repaint add a call to super or use clearRect or fillRect (with the background color set, of course). If you don't do this you will get artifacts in your graphics.
class GraphicComponent extends JPanel {
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // carry on...
}Paint code is the place to render graphics and images, not for adding components. Add your components to the GUI in or via init. Generally is is useful to keep your drawing component separate from your other components.
class GUIClass extends JApplet implements ActionListener {
    public void init() {
        JPanel buttonPanel = getButtonPanel();
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(buttonPanel, "South");
        getContentPane().add(new GraphicComponent());  // default center section
    private JPanel getButtonPanel() {
        JPanel panel = new JPanel(null);
        JButton[] plateaux = nw JButton[13];
        for(int i=0;i<plateaux.length;i++) {
            System.out.println("buton ok"+i);
            plateaux=new JButton("button " + i);
plateaux[i].setEnabled(true);
plateaux[i].addActionListener(this);
Color cri=new Color(240-15*i,0,0);
plateaux[i].setBounds(130,60+30*i,139,15);
plateaux[i].setBackground(cri);
panel.add(plateaux[i]);

Similar Messages

  • Where can I find the entries of all components in NWSP15

    hi all,
         how can i find the url or command for all the componnents' entry.
      1.visual administrator: ..usr\sap\J2E\JC00 \j2ee\admin\go.bat.
      2.config tool:..usr\sap\J2E\JC00\j2ee\configtool\configtool.bat
      3.portal: http://localhost:50000/irj
      then,I want to know,where is entry of BI,EXCHANGE SERVER and so on.
      is there any useful url to use?
      thank you very much.

    There is no list available from your end; you need either physical or network access to a computer to individually deauthorize it. If you're out of authorizations, use the Deauthorize All function.
    (83362)

  • How to set the background for all components?

    hi
    Does anybody know how to set the DEFAULT background color in an application.. I need it because in jdk 1.3 the default bgcolor is grey and in 1.5 it is white.. and I wish white as well.. so to make it also white in jdk 1.3 I need to use the (a bit annoying) anyContainer.setBackground( Color.white ); and these are lots in my app.. So my question is: is there such an overall class with a function (say UIManager.setComponentsBackground( Color color ) ) for such a purpose?
    any tip or link would be greatly appreciated

    Does anybody know how to set the DEFAULT background color in an applicationthis might get you close
    import java.awt.*;
    import javax.swing.*;
    import java.util.Enumeration;
    class ApplicationColor extends JFrame
      public ApplicationColor()
        setApplicationColor(Color.RED);
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel jp = new JPanel(new BorderLayout());
        jp.add(new JTextField("I'm a textfield"),BorderLayout.NORTH);
        jp.add(new JComboBox(new String[]{"abc","123"}),BorderLayout.CENTER);
        jp.add(new JButton("I'm a button"),BorderLayout.SOUTH);
        getContentPane().add(jp);
        pack();
      public void setApplicationColor(Color color)
        Enumeration enum = UIManager.getDefaults().keys();
        while(enum.hasMoreElements())
          Object key = enum.nextElement();
          Object value = UIManager.get(key);
          if (value instanceof Color)
            if(((String)key).indexOf("background") > -1)
              UIManager.put(key, color);
      public static void main(String[] args){new ApplicationColor().setVisible(true);}
    }

  • Avoid repaint in JLayeredPane components

    I have a program including a JLayeredPane that contains a JComponent and a JPanel. Both components are set on different layers of the JLayeredPane.
    I use the JPanel for painting, so I want to avoid unnecessary repaints if I can. The problem is that when I resize the JComponent using setBounds(), the JLayeredPane performs a repaint, and consequently, the JPanel too.
    How can I avoid the repaint propagation through all the JLayeredPane? I tried to use setIgnoreRepaint(true), but it didn't seem to work.
    If you need to see some code, just ask. Thanks in advanced. :)

    Sorry for not sending my SSCCE before; there was mealtime here. Thanks for your code anyway, I'll have a look now to see if I get any idea.
    This is my code. What I'd like to avoid it's to display the setence "inner painted" (it means that the paintComponent() method of the innerPanel has been triggered):
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.event.MouseEvent;
    import javax.swing.BoxLayout;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLayeredPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.event.MouseInputListener;
    public class SelectionFrame implements MouseInputListener {
        private final static int CURSOR_WIDTH = 2;
        private final static int ALPHA_SELECTION_INT = 20;
        private JFrame frame;
        private JScrollPane scrollPane;
        private JPanel innerPanel;
        private JPanel outerPanel;
        private JComponent transComponent;
        private JLayeredPane layeredPane;
        private boolean cursorEnabled;
        private boolean selectionEnabled;
        private Color bgColor;
        public SelectionFrame() {
            cursorEnabled = true;
            selectionEnabled = true;
            frame = new JFrame();
            frame.setTitle("Adilo Selection");
            frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),
                    BoxLayout.X_AXIS));
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setMinimumSize(new Dimension(400, 300));
            bgColor = Color.CYAN;
            innerPanel = new JPanel()  {
                @Override
                protected void paintComponent(Graphics g)   {
                    System.out.println("inner painted");
            innerPanel.setBackground(bgColor);
            outerPanel = new JPanel();
            outerPanel.setBackground(Color.BLUE);
            outerPanel.setBounds(0, frame.getHeight() / 3, frame.getWidth(), frame.getHeight() / 3);
            transComponent = new JComponent()
                @Override
                public void paintComponent(Graphics g)
                    Color selectionColor = new Color(255 - bgColor.getRed(),
                            255 - bgColor.getGreen(),
                            255 - bgColor.getBlue(),
                            ALPHA_SELECTION_INT);
                    g.setColor(selectionColor);
                    g.fillRect(0, 0, getSize().width, getSize().height);
            layeredPane = new JLayeredPane();
            layeredPane.add(innerPanel, new Integer(1));
            layeredPane.add(outerPanel, new Integer(2));
            layeredPane.add(transComponent, new Integer(3));
            scrollPane = new JScrollPane();
            scrollPane.setViewportView(layeredPane);
            innerPanel.setBounds(0, 0, frame.getWidth(), frame.getHeight());
            innerPanel.addMouseListener(this);
            innerPanel.addMouseMotionListener(this);
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);
        private int initXPos;
        public void mousePressed(MouseEvent e) {
            initXPos = e.getX();
            if(cursorEnabled)    {
                transComponent.setBounds(e.getX(), 0, CURSOR_WIDTH, frame.getHeight());
        public void mouseReleased(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
        public void mouseDragged(MouseEvent e) {
            int xPos = e.getX();
            if(selectionEnabled)    {
                if(xPos > initXPos) {
                    transComponent.setBounds(initXPos, 0, xPos - initXPos, frame.getHeight());
                else    {
                    transComponent.setBounds(xPos, 0, initXPos - xPos, frame.getHeight());
        public void mouseMoved(MouseEvent e) {
        public void mouseClicked(MouseEvent e) {
        public static void main(String[] args) {
            new SelectionFrame();
    }

  • Change BgColors, FgColors for all Components in a Container?

    Is there a possibility to change the Background Color, the Foreground Color and the Fontsettings for all Components in a Container? Each Component in the Container should get the Colorsettings of the Container...

    Just overwrite the add, setBackground(), setForeGround() and the Font-methods of the Container:
    public void add(Component c){
    super.add(comp);
    comp.setBackground(...);
    comp.setForeground(...);
    //...the Font-stuff
    public void setBackground(Color c){
    for(int i=0;i< getComponentCount(), ++i){
    getComponenetAt(i).setBackground(c);
    //the same for setForeground and the Font-methods.

  • Running Mavericks on an iMac 2.7 GHz Intel Core i5, I've been trying to install Adobe CS3. All components install except InDesign. Is this an installation disk problem or is it not compatible with the OS?

    Running Mavericks on an iMac 2.7 GHz Intel Core i5, I've been trying to install Adobe CS3 Design Premium. All components install except InDesign. Is this an installation disk problem, or is there a compatibility problem with the OS?

    I fear that you are trying to download OLDER Software on a newer Operating Sysytem Meaning that you need to Install the Latest Version of Adobe on the Newer Operating System for it to work Properly. Be sure to always check the minimum System Requirements.

  • On my MacBook with Lion Safari does start, does not react immediately after trying to open it. Installing a new Safari does not help. Removing parts of Safari in the Library did not help. Where can I find and remove all components (LastSession ...)?

    How can I reset Safari with all components? On my MacBook with Lion, Safari does not start, does not react immediately after trying to open it. Installing a new Safari does not help. Removing parts of Safari in the Library does not help. Where can I find and remove all components as LastSession and TopSites?

    The only way to reinstall Safari on a Mac running v10.7 Lion is to restore OS X using OS X Recovery
    Instead of restoring OS X in order to reinstall Safari, try troubleshooting extensions.
    From the Safari menu bar click Safari > Preferences then select the Extensions tab. Turn that OFF, quit and relaunch Safari to test.
    If that helped, turn one extension on then quit and relaunch Safari to test until you find the incompatible extension then click uninstall.
    If it's not an extensions issue, try troubleshooting third party plug-ins.
    Back to Safari > Preferences. This time select the Security tab. Deselect:  Allow plug-ins. Quit and relaunch Safari to test.
    If that made a difference, instructions for troubleshooting plugins here.
    If it's not an extension or plug-in issue, delete the cache.
    Open a Finder window. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following
    ~/Library/Caches/com.apple.Safari/Cache.db
    Click Go then move the Cache.db file to the Trash.
    Quit and relaunch Safari to test.

  • HT201413 I am running Windows 7, ITUNES 10.6.3.25.  I am unable to see my Iphone/sync my iphone in Itunes.  I have uninstalled all components of Itunes and downloaded the newest version to no avail.  Please help.....Thanks

    I am running Windows 7, ITUNES 10.6.3.25.  I am unable to see my Iphone/sync my iphone in Itunes.  I have uninstalled all components of Itunes and downloaded the newest version to no avail.  Please help.....Thanks 
    I am attaching the Diagnostics data below:
    Microsoft Windows 7 x64 Home Premium Edition Service Pack 1 (Build 7601)
    Dell Inc. Inspiron N7010
    iTunes 10.6.3.25
    QuickTime not available
    FairPlay 1.14.43
    Apple Application Support 2.1.9
    iPod Updater Library 10.0d2
    CD Driver 2.2.0.1
    CD Driver DLL 2.1.1.1
    Apple Mobile Device 5.2.0.6
    Apple Mobile Device Driver 1.59.0.0
    Bonjour 3.0.0.10 (333.10)
    Gracenote SDK 1.9.6.502
    Gracenote MusicID 1.9.6.115
    Gracenote Submit 1.9.6.143
    Gracenote DSP 1.9.6.45
    iTunes Serial Number 0016AA9C0126E318
    Current user is not an administrator.
    The current local date and time is 2012-07-05 11:42:18.
    iTunes is not running in safe mode.
    WebKit accelerated compositing is enabled.
    HDCP is supported.
    Core Media is supported.
    Video Display Information
    Intel Corporation, Intel(R) HD Graphics
    **** External Plug-ins Information ****
    No external plug-ins installed.
    **** Device Connectivity Tests ****
    iPodService 10.6.3.25 (x64) is currently running.
    iTunesHelper 10.6.3.25 is currently running.
    Apple Mobile Device service 3.3.0.0 is currently running.
    Universal Serial Bus Controllers:
    Intel(R) 5 Series/3400 Series Chipset Family USB Enhanced Host Controller - 3B34.  Device is working properly.
    Intel(R) 5 Series/3400 Series Chipset Family USB Enhanced Host Controller - 3B3C.  Device is working properly.
    No FireWire (IEEE 1394) Host Controller found.
    Most Recent Devices Not Currently Connected:
    iPod (5th generation) running firmware version 1.3
    Serial Number:       8L643QK9V9R
    iPhone 4 (CDMA) running firmware version 5.1.1
    Serial Number:       C8RG57F0DDP8
    **** Device Sync Tests ****
    No iPod, iPhone, or iPad found.

    I did all that HT1925 recommended and it was no help.  My computer still won't recognize my iPhone.  Often trying to start Apple Mobile Device Service fails with an error message that it starts and then stops immediately.

  • On my itouch 4th gen, I use imessage and message many people, but sometimes when i send a message the send bar on top will go almost all the way and stop. This will happen for some time and then work later. is there anything to avoid the freezinginsending

    On my itouch 4th gen, I use imessage and message many people, but sometimes when i send a message the send bar on top will go almost all the way and stop. This will happen for some time and then work later. is there anything to avoid the freezing problem while it sends

    See:
    iOS: Troubleshooting Messages
    However, I suspect it is just a tempery network problem beyond your control

  • Resizing a Window and proportionately varying the size of all it components

    Hi,
    I am writing a java application in which I am creating different componets like Panels, Canvas, ScrollPane etc. on a Frame. When I resize this Window, I want to proportionately vary the sizes of all its components. Any idea how I can do that ?
    Thanks,
    Arun

    Panels, Canvas, ScrollPane etc. on a FrameThose are all AWT Components. This is a Swing forum.
    Also its about time you learned to respond to the suggestions you've been given in the past so people know if the advice given is helping or not. Otherwise we will just stop answering questions since it appear you are ignoring all the suggestions.

  • After the last update on iTunes I have not been able to get into the program. I have uninstalled all components and reinstalled and now it is telling me I am missing .dll files. I am so frustrated. I probably lost my entire library except what I purchased

    After the lastest update on iTunes I have not been able to get into the program. I have uninstalled all components and reinstalled and now it is telling me I am missing .dll files. I am so frustrated. I probably lost my entire library except what I purchased

    Your library should be safe.
    See Troubleshooting issues with iTunes for Windows updates.
    tt2

  • All components not updating when I change the L&F

    I have developed a GUI and want Windows LookAndFeel for it. Please excuse me if I use some terms incorrectly. I'll explain my class structure first -
    1. class MainWindow - Contains the main method and invokes MainFrame
    2. class MainFrame - Creates the basic GUI and all the components and their event-handlers
    3.class MainPanel - Contains the actions to be taken in response to an event in MainFrame
    4. Dialog Boxes : Their are several classes implementing several dialog boxes which I load as needed.
    I have changed the L&F in the MainFrame class after all the MainFrame class components have been loaded. I have also used updateComponentTreeUI( ) to update all components already formed. I found out that not all components are having the Windows L&F when I tried out a JProgressBar. Instead of the green-broken progress indicator (Windows XP style), it was showing the gray-filled indicator (Java style). Then I noticed even the Menu Items are having the default L&F. Can anyone comment. Not giving any code because I am not sure which part of the huge GUI code should I post, i.e. where the problem really lies.

    You just said it doesn't work for a menu. So you
    create a frame with a menu and a menu item. About 10
    lines of code. Then you add two buttons one to switch
    to the Windows LAF the other to the Metal LAF.
    Another 10 lines of code. Now you have your demo
    program.No no, you din't get me. I know the basics regarding L&F. All the components are working fine, but that JProgressBar is not showing the XP view. Forget the JMenuItems, I am not sure the view is Windows L&F or Metal L&F, but I am sure the JProgressBar is not Windows L&F (while the rest of the components in the dialog box are perfect). Could this be due to something that I missed out while implementing the JProgressBar. But the Windows L&F is loaded before the dialog box containing the progress bar comes in. Your answer to my last Swing post helped me a lot. Hope you (or anyone else) can help me with this too

  • Avoid to repaint() all JComponents.

    Hello,
    I have the following problem with my program.
    I have a JComponent A and to this I a added
    three other JComponents B,C,D.
    JComponent A = new JComponent();
    JComponent B = new JComponent();
    JComponent C = new JComponent();
    JComponent D = new JComponent();
    A.add(B);
    A.add(C);
    A.add(D);
    But now when I do a repaint, i.e. on JComponent D, all other JComponents
    do a repaint() either.
    That is very wastefully, because in one of the JComponents I made very
    expensive mathematical calculations in the paint() mehtod and I only want to make them once. But in the front JComponent I have to do the repaint() very often.
    Please Help !!!!
    Thank's in advance.
    Regards
    Oli

    This probably isn't what you want to hear but the solution to your problem is... Don't do expensive mathmatical calculations inside the paint() method, especially if you only want to do them once. Remember your not the only one calling paint(). Paint() gets called by many other processes so your best bet is to put the math in its own method and call it once and only once when you want it.

  • Just installed today Acrobat XI standard on PC w Windows 7, did use the Typical installation but now would like to install all components. What shall I do ? T y

    Just installed today Acrobat XI standard on PC w Windows 7, did use the Typical installation but now would like to install all components. What shall I do ? T y

    restart installation and pick whatever options you want to install.

  • How to wait until all components painted?

    Hi - I have searched for hours for an answer to this and have yet to find something so any help is much appreciated!
    Ive posted some code below to simulate the problem im facing. This is a simple frame which has a couple of custom jPanels embedded within it.
    When this is run, the first 3 lines i see are:         I want this comment to be the last thing output
            Now finished panel paint
            Now finished panel paintBut, as this output suggests, i want the "I want this comment to be the last thing output" line to be displayed after the two panels are completely painted on the screen (in real life i need to know my components are displayed before the program can move on to further processing). Of course, if you cause a repaint you see the "now finished panel paint" each time, but im not interested in this, im simply interested in how to overcome this when the frame is first created and shown.
    Ive tried everything i can think of at the "// ***** What do i need to put here? ******" position but nothing seems to work... In short my question is how can i construct my frame and get it to ensure that all components are fully displayed before moving on?
    Sorry if the answer to this is obvious to someone who knows these things, but its driving me mad.
    Cheers
    import javax.swing.*;
    import java.awt.*;
    public class Frame1 extends JFrame {
      public static void main(String[] args) {
        Frame1 frame1 = new Frame1();
        // ***** What do i need to put here? ******
        // to ensure that the System.err.. call below
        // is only executed once both panels paint methods
        // have finished?????
        System.err.println("I want this comment to be the last thing output");
        System.err.flush();
      public Frame1() {
        this.getContentPane().setLayout(new FlowLayout());
        MyPanel  p1 = new MyPanel(); p1.setBackground(Color.red);
        MyPanel  p2 = new MyPanel(); p2.setBackground(Color.green);
        this.getContentPane().add(p1, null);
        this.getContentPane().add(p2, null);
        this.pack();
        this.setVisible(true);
      class MyPanel extends JPanel {
        Dimension preferredSize = new Dimension(200,200);
        public Dimension getPreferredSize() { return preferredSize;  }
        public MyPanel () { }
        public synchronized void paintComponent(Graphics g) {
          super.paintComponent(g);  //paint background
          // do some irrelevant drawing to simulate a bit of work...
          for (int i=0; i<200; i+=20) {
            g.drawString("help please!",50,i);
          System.err.println("Now finished panel paint"); System.err.flush();
        } // end of MyPanel
      }

    Thanks both for your replies.
    When doing the "Runnable runnable = new Runnable(){public void run(){ frame1.paint(frame1.getGraphics());....." method i sometimes see
        Now finished panel paint
        Now finished panel paint
        I want this comment to be the last thing output       
        Now finished panel paint
        Now finished panel paintwhich is a pain.
    As for making a new Runnable to do the system.err.println and then doing the SwingUtilities(invoke) on that runnable, that didnt work for me at all.
    So... in the end, my solution was to have the paint method set a boolean when finished and the main program sleep while this is false
         // Dont want to sleep for say a few seconds as cant be sure
         //painting will be finished, must monitor state of painting ...
         //therefore use while loop
         while (!isOk) {  // isOk is true when both panel paint methods complete
             System.err.println("Waiting......");
             try{   Thread.sleep(300 /* wait some time */);  }
             catch(Exception e){}
           System.err.println("Thankfully this works");which is a kind of mixture of both your suggestions i guess!
    Thanks for your help, much appreciated.

Maybe you are looking for

  • Cannot Find Photos on External Hard Drive Using iPhoto and Time Machine

    Hi everyone, This is my first time posting on this forum and am really hoping for some help! I have a 2006 PowerBook G4 that is running iPhoto and Time Machine, and I've used an external hard drive to backup everything on the computer via Time Machin

  • Restore mysql doesn't work with Runtime?

    hi all iam trying to restore a backup of mysql database,i took the backup using mysqldump. iam using a correct syntax of restoring and i already tested it in the command line and it worked correctly mysql -u root new_db < f:\backup.sql the problem is

  • Burned DVD's Are Pixelated  And Not Great Quality

    So I have some movies on my computer that I tried burning to a DVD disc on my Macbook Pro. On my laptop the quality is really good but when I put it on a DVD it looks kind of terrible on my TV. Now I understand it could be because the whole aspect de

  • Error Message no. 00398 in Goods Issue

    Hi, We are getting error at the time of Goods Issue posting against reservation with movement 281 (network) as below. ERROR 25.000- Message no. 00398 Diagnosis Placeholder for batch input error text, this message is not output. 25.000- Please help fo

  • Destination number format incorrect error message

    I have recently upgraded to a 5c from android and for some contacts, even iPhone numbers, can't send a message. Keep getting destination number format incorrect. Happens even after I edit contacts data