Problem on Swing TextArea

I want to display characters in TextArea with Upper case only. If customer input some data in a TextArea, by default the entered data should appear in Upper Case only in the TextArea, incase user enters in Lower case also. Can anyone please provide me a solution to my problem.
Thanks

Thanks alot its working with your solution. One more question What listener is used for JTextArea? for AWT TextArea, there is a textlistener, and writing code in textValuechanged() method, like this is there any way for JTextArea in Swings.
Thanks for your help,

Similar Messages

  • TextArea problem (non-swing)

    How can I get a TextArea to show whatever item I click on a Checkbox?

    Add an ItemListener to the CheckBox. In the itemStateChanged method of the listener, check the state of the CheckBox and add the appropriate text to the TextArea.

  • Problem in Swing tree root node when displaying Japanese

    I'm trying to create a tree using DefaultTreeModel. The root node will display text in Japanese and the other child nodes are in English. My problem is the root node fails to show Japanese correctly (only squares are shown).
    I've already set my font.properties.ja to display Japanese font for virtual font "dialog":
    dialog.plain.0=Arial,ANSI_CHARSET
    dialog.plain.1=\uff2d\uff33 \u30b4\u30b7\u30c3\u30af,SHIFTJIS_CHARSET
    dialog.plain.2=WingDings,SYMBOL_CHARSET,NEED_CONVERTED
    dialog.plain.3=Symbol,SYMBOL_CHARSET,NEED_CONVERTED
    And I've checked the "Tree.font" of UIManager is:
    Tree.font = javax.swing.plaf.FontUIResource[family=dialog,name=Dialog,style=plain,size=12]
    I'm quite sure that my font.properties.ja is correct as all message dialogs in my app. shows Japanese correctly (also using the same dialog font).
    I got stuck. Can anyone please give me some advice? Thanks in advance.

    hello!
    first of all i am sorry that i cannot help u.
    i am a java developer and start work on
    Arabic ( one of the langugae supported by
    unicode) text editing.If u have any knowledge that
    what i should do to display the text in this language
    in a textarea.when i run a code,this display only
    square.
    plz help me.i will be realy thankful to u.
    Qaiser Mehmood
    [email protected]

  • Design problem with Swing

    Hi all. I've run into some design problems when trying to create a Swing app.
    I've got a non-graphical class that emulates a power supply unit. Let's call it PSUnit. I have to create a GUI for PSUnit.
    Every class designed to build a full GUI app uses PSUnit in some way (changes its voltage, displays voltage, turns it on, turns it off, etc.)
    Here's the catch. Suppose I've got a class:
    public class BuildingBlock extends JPanel {
         // code includes a JTextBox displaying
         // the current PSUnit voltage.
    }another class is created for setting the voltage:
    public class AnotherBlock extends JPanel {
         // this class contains a JSpinner and
         // a button that retrieves the JSpinner value
         // and sets it as the current voltage of
         // PSUnit
    }When the button in AnotherBlock is clicked, I must notify the BuildingBlock class that a PSUnit has changed its state so it can update it's values and display the correct data.
    I've tried to do this a few times but failed miserably, so I'm hoping you guys could help me out.
    Please note that both of the above classes have some additional code and it's not very pleasant to make one class an inner class of another. I should be able to create a "standalone" classes which, combined together, form a GUI for PSUnit.
    Thanks.

    Yes this is a common problem that many of us have when building UIs
    Here's the question: In this instance, are these two classes really independant? Could they stand alone? Often when building a GUI, it's not even that easy to answer that question, but these leads to the two ways you can solve this
    #1. Make them independent, and use listeners either using Observable / Observer or creating your own custom listeners. The advantage of this is smaller classes and more independence. The disadvantage is it's generally more complicated, especially at the design stage
    #2 (what I'd probably recommend). Make 1 GUI class "MyPSFrame", then declare your panel classes as inner classes within that class. This way, everything goes into one spot, and everything is shareable. This also makes sense if you can't have 1 of the panels without the other.

  • Help with problems in Swing

    Hi, I am trying to develop a simple applet where a user can click on the screen to add jbuttons at the location of the mouse click. I have written an overly complex set of code that tries to achieve this goal, and in the end I have come close. My applet allows the user to input a certain number, and then click that many times on screen to create more jbuttons. The problem is that whenever the user clicks on screen a jbutton is created, but it only appears once the mouse has moved over it. I find this pretty weird, but basically when the user clicks, a jbutton is created within the program, but it is only "drawn" to the screen when the mouse moves directly over it.
    www.geocities.com/nickv360
    Can anyone explain to me why this is happening?
    http://www.geocities.com/nickv360/Source/AirlineModel.java
    http://www.geocities.com/nickv360/Source/City.java
    http://www.geocities.com/nickv360/Source/DrawingCanvas.java
    These are the source files if that helps at all. Addtinonally, the reset button doesn't work. The way the applet is supposed to be set up is to have an array of cities (JButtons) stored in DrawingCanvas. The drawing Canvas then accesses that cities[] array and adds each city[i] to the map. If there are no cities in the cities[] array, then no cities will be added. So, in order to successfully reset the map, here is what I do:
    cities = new City[numCities];
    removeAll();
    index = 0;
    repaint();
    I change the cities[] array to a new array of cities. I use the removeAll() method to take away all the JButtons that are currently on the map, I reset the index counter, and I repaint. Unfortunately this doesn't work.
    Does anyone know why Swing won't paint my buttons until the mouse moves over them, and why the reset method I've written doesn't work? Thanks in advance to anyone who can help.

    Just wanted to let people know that I found the answer:
    As for the other problem, I think it has to do with you having overridden paint. Normally, when you call repaint on a container, it will automatically call repaint on all the components that it contains. I'm fairly certain that if you don't manually call super.paint(g); in your paint method, it won't do it for you.
    Calling super.paint(g) makes the all of the bugs in the code disappear.
    Thanks.

  • Character reordering problem in swing text components  on macintosh

    I have created a swing application that handles devanagari script.(script for Hindi language).The application works perfectly in windows but in apple macintosh
    there is a problem with the reordering of characters in text componets. Reordering means some characters needs to be displayed not in the exact order in which they are stored.I was wondering how this can happen as the application works fine on windows.Also other applications like text editor displays devanagari script correctly on macintosh.
    I tried with several fonts like Arial Unicode MS,Devanagari MT etc/.java

    Very odd. Post your Reordering code.

  • Thread problem in swings

    I have made an application in swings i have stored the class files in a system and call that class files by a batfile shortcut in two diff. pcs .and i am tring to get an value of a Jtextarea in an event When I tried to run this application at the same time from 2 diff PCS,with diff string input in text area It is giving me the same vlaue.
    Tell me Y it is so.and how can i rectify it
    javauser

    Very strange... what makes you think that this is a threading problem?

  • Thread problem in swing application?

    Hi,
    I have a doubt in GridLayout and Threads. I�m doing one small application which is accepting images and Alphabets. Actually, What I�m doing running images and alphabets(combinedly) in frequent intervals. For this I used GridLayout and Thread concept. But I have a problem in paint method. How to call the GridLayout frequently. In GridLayout , I�m putting Images and alphabets. Acutually in paint method , there are only drawString or drawImage or other methods. Is it possible to call my layout. Is so, can anybody help me in this regard. Is there any way to do it . please suggest me.
    Thanks,
    -Balaji
    My code follows:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    import java.awt.Color;
    import javax.swing.*;
    import java.applet.Applet;
    import java.util.*;
    import java.io.*;
    public class GridLayEx2 extends Applet implements Runnable {
    private Random r = new Random();
    private Thread imageThread = null;
    GridLayout glt;
    public void init() {
    glt = new GridLayout(3,3);
    setLayout(glt);
    } // end of init method
    public void start(){
    if (imageThread == null) {
    imageThread = new Thread(this, "GridLayEx2");
    imageThread.start();
    } // end of start method
    public void run(){
    Thread myThread = Thread.currentThread();
    while (imageThread == myThread) {
    repaint();
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e){ }
    }// end of run method
    public void paint(Graphics g){
    Font boldFont = new Font("Helvetica", Font.BOLD, 25);
    Font plainDerived =
    boldFont.deriveFont(Font.PLAIN, 25);
    JLabel myLabel[] = new JLabel[9];
    String myUrl = "C:\\Regoti\\Vision\\AP\\Project\\Version1\\images\\duke1.gif";
    myLabel[0] = new JLabel(new ImageIcon(myUrl));
    myLabel[1] = new JLabel("A");
    myLabel[2] = new JLabel("A");
    myLabel[3] = new JLabel("A");
    myLabel[4] = new JLabel("A");
    myLabel[5] = new JLabel("A");
    myLabel[6] = new JLabel("A");
    myLabel[7] = new JLabel("A");
    myLabel[8] = new JLabel("A");
    myLabel[1].setFont(boldFont);
    myLabel[2].setFont(boldFont);
    myLabel[3].setFont(boldFont);
    myLabel[4].setFont(boldFont);
    myLabel[5].setFont(boldFont);
    myLabel[6].setFont(boldFont);
    myLabel[7].setFont(boldFont);
    myLabel[8].setFont(boldFont);
    int values[] = new int[9];
    values = gen_pos_uni_ran_num(0,8);
    for(int i = 0; i < 9; i++)
    add(myLabel[values]);
    } // end of paint method
    public void stop(){
    imageThread = null;
    } // end of stop method
    public int[] gen_pos_uni_ran_num(int min, int max)
    int results[] = new int[Math.abs(max - min) + 1];
    for(int i = 0; i < results.length; ++i)
    results = -1;
    outer_loop:
    for(int i = 0; i < results.length; ++i)
    int random_int = (int)((Math.random() * results.length) + min);
    for(int j = 0; j < results.length; ++j)
    if(results[j] == random_int)
    random_int = (int)((Math.random() * results.length) + min);
    j = -1;
    continue;
    if(j == results.length - 1)
    results = random_int;
    continue outer_loop;
    return results;
    } // generate unique random numbers
    public static void main( String args[])
    Frame GridLayFrame = new Frame ( " Grid Layout Frame ");
    GridLayEx2 gl = new GridLayEx2();
    gl.init();
    GridLayFrame.add(gl);
    GridLayFrame.pack();
    GridLayFrame.setSize(GridLayFrame.getPreferredSize());
    GridLayFrame.show();
    GridLayFrame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    } // end of main method

    hi,
    i got one doubt in the previous application. i want to put labels in the circle manner while changing my label positions. Now it is rectangular type. And also i want to change my background color of JFrame. Please see my code ...
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    import java.awt.Color;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.util.GregorianCalendar;
    public class GridLayEx6 extends JApplet{ 
       private Random r = new Random(); 
       private ActionListener taskPerformer;
       private javax.swing.Timer timer;  
       private GridLayout glt;  
       private JLabel[] myLabel;     
       GregorianCalendar todayDate = new GregorianCalendar();     
       long fromTime,toTime,elapsedTime;
       public void init() {     
            glt = new GridLayout(3,3);     
          Font boldFont = new Font("Helvetica", Font.BOLD, 25);     
          Font plainDerived = boldFont.deriveFont(Font.PLAIN, 25);     
             myLabel = new JLabel[9];     
             String myUrl = "C:\\Regoti\\Vision\\AP\\Project\\Version1\\images\\MyArrow.jpg";
             String myUrlA = "C:\\Regoti\\Vision\\AP\\Project\\Version1\\images\\MyA.jpg";     
             URL url = null;     
       try{
       myLabel[0] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);     
       myLabel[1] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[2] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[3] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[4] = new JLabel("+", SwingConstants.CENTER);     
       myLabel[5] = new JLabel(new ImageIcon(myUrlA), SwingConstants.CENTER);
       myLabel[6] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[7] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[8] = new JLabel(new ImageIcon(myUrl), SwingConstants.CENTER);
       myLabel[2].setVerticalAlignment(SwingConstants.NORTH);     
       myLabel[4].setFont(boldFont);     
       getContentPane().setLayout(glt);     
      } catch( Exception e)
        { System.out.println(" Exception occurs "+e);}
       int delay = 20000; //milliseconds     
       ActionListener taskPerformer = new ActionListener() {     
       public void actionPerformed(ActionEvent evt) {      
                 randomDuke();
       timer = new javax.swing.Timer(delay, taskPerformer);     
       addKeyListener(new KeyAdapter()      {        
          public void keyPressed(KeyEvent e){           
                 GridLayEx6 gl2 = (GridLayEx6)e.getSource();           
                     switch(e.getKeyCode())
                           case(KeyEvent.VK_ENTER): 
                                gl2.randomDuke();                 
                                break;
                       case(KeyEvent.VK_SPACE):              
                            if(gl2.timer.isRunning())                    
                              { gl2.timer.stop();                 
                                    toTime = System.currentTimeMillis();
                                 elapsedTime = toTime - fromTime;
                                 System.out.println("toTime : "+toTime);
                                 System.out.println("elapsedTime : "+elapsedTime);
                                  gl2.timer.start();
                                   gl2.randomDuke();
                               break;
                       case(KeyEvent.VK_KP_RIGHT):case(KeyEvent.VK_KP_UP):              
                       case(KeyEvent.VK_RIGHT):case(KeyEvent.VK_UP):              
                         int delay = gl2.timer.getDelay();
                         if(delay > 0)                    
                            gl2.timer.setDelay(delay - 100);                 
                            break;
                       case(KeyEvent.VK_KP_LEFT):case(KeyEvent.VK_KP_DOWN):              
                       case(KeyEvent.VK_LEFT):case(KeyEvent.VK_DOWN):
                            int delay = gl2.timer.getDelay();                  
                            if(delay < 10000)                    
                                 gl2.timer.setDelay(delay + 100);                  
                                 break;
                       //timer.start();  
             } // end of init method  
             public void start()   {     
                  timer.start();     
                    while(!isFocusOwner())        
                            requestFocus(); 
             } // end of start method     
             public void stop(){    
                  timer.stop();
            } // end of stop method     
             /** To make sure we have focus in application *  
             * mode if JFrame loses focus control          *  
             * - non standard usage of paintComponent      */    
             public void paintComponent(Graphics g)   {
                  while(!isFocusOwner())        
                       requestFocus();  
            public void randomDuke()   {     
                  fromTime = System.currentTimeMillis();
                  System.out.println("fromtime : "+fromTime);     
                  getContentPane().removeAll();     
                  int[] values = new int[9];     
                  int temp;
                  values = gen_pos_uni_ran_num(0,8);     
                  for ( int i=0; i<=8;i++)
                          if ( values[i] == 4)
                                 temp = 4;
                                 values[i] = values[4];
                                 values[4] = temp;
                  for(int q = 0; q < 9; q++)   
                        getContentPane().add(myLabel[values[q]]);    
                       myLabel[0].revalidate();
                       myLabel[1].revalidate();
                       myLabel[2].revalidate();
                       myLabel[3].revalidate();
                       myLabel[5].revalidate();
                       myLabel[6].revalidate();
                       myLabel[7].revalidate();
                       myLabel[8].revalidate();
                    } // end of randomDuke method  
              public int[] gen_pos_uni_ran_num(int min, int max)   {     
                  int results[] = new int[Math.abs(max - min) + 1];     
                  for(int q = 0; q < results.length; ++q) 
                       results[q] = -1;     
                  outer_loop:     
                  for(int q = 0; q < results.length; ++q)  
                       int random_int = (int)((Math.random() * results.length) + min);        
                    for(int j = 0; j < results.length; ++j)       
                        if(results[j] == random_int)            {              
                            random_int = (int)((Math.random() * results.length) + min);              
                            j = -1;
                      continue;           
                     if(j == results.length - 1)
                          results[q] = random_int;              
                          continue outer_loop;
                  return results;  
                  } // generate unique random numbers  
                  public static void main( String args[])
                        JFrame GridLayFrame = new JFrame ( " Grid Layout Frame ");     
                       GridLayFrame.setSize(500,500);     
                       GridLayEx6 gl = new GridLayEx6();     
                       gl.init();     
                       GridLayFrame.getContentPane().add(gl);     
                       //GridLayFrame.setBackgroundColor(Color.white);
                       GridLayFrame.setVisible(true);
                       gl.start();     
                       GridLayFrame.addWindowListener(new WindowAdapter()      
                         public void windowClosing(WindowEvent e)         
                        System.exit(0);         }      });  
                  } // end of main method
                  }

  • Problem in Swing Component (JComboBox)

    Hello i've got one amazing problem in my Swing Component (JComboBox) while testing for Glasspane..
    Please check this photo http://www.flickr.com/photos/39683118@N07/4483608081/
    Well i used Netbeans Drag n Drop Swing so the code might be messing..any way my code looks like this:
    My code looks like this:
    public class NewJPanel extends javax.swing.JPanel {
        /** Creates new form NewJPanel */
        public NewJPanel() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jTextField1 = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jComboBox1 = new javax.swing.JComboBox();
            jCheckBox1 = new javax.swing.JCheckBox();
            setOpaque(false);
            jTextField1.setText("jTextField1");
            jLabel1.setText("jLabel1");
            jLabel2.setText("jLabel2");
            jLabel3.setText("jLabel3");
            jButton1.setText("jButton1");
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
            jComboBox1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
            jComboBox1.setNextFocusableComponent(jCheckBox1);
            jComboBox1.setOpaque(false);
            jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jComboBox1ActionPerformed(evt);
            jCheckBox1.setText("jCheckBox1");
            jCheckBox1.setOpaque(false);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(119, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3))
                    .addGap(51, 51, 51)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButton1)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jCheckBox1)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(115, 115, 115))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(70, 70, 70)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1))
                    .addGap(15, 15, 15)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jCheckBox1))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addComponent(jButton1)
                    .addContainerGap(93, Short.MAX_VALUE))
            jComboBox1.getAccessibleContext().setAccessibleParent(null);
        }// </editor-fold>
        private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JCheckBox jCheckBox1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration
    }

    For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org], that demonstrates the incorrect behaviour.

  • Thread problems in Swing

    I'm building I guess its like an online strategy game. On the map, when you move your mouse to within 50 of the bounds of the applet, it'll start scrolling the map at a predetermined speed.
    When working with applets/painting/threads this worked like a dream. Java was too fast for itself and I had to even slow the scrolling down.
    Now, I'm building the whole thing in swing instead. The map is technically a JLabel inside of a Container that gets loaded into the main contentPane.
    The only way I could use setLocation in my threads run method was to setLocation on the Container, not the JLabel. Odd fix to that problem. (I kept getting a null pointed exception otherwise)
    My problem is, when the mouse is in that 50 pixels, the program knows it, but it just /lags/. Horribly. I set a counter to print to the console and when the mouse enters the area it moves to like 15 (in 0.001 seconds), and stops. I move my mouse around, and a few seconds later I see 700-705, then it stops, and jumps ahead again if I move my mouse.
    So my program will now scroll the map in very small, /very/ jagged bits.
    It's not an intensive program or code. I don't see how or why the thread can't continually run it.
    My run method:
    public void run() {
              while (true) {
                   if (mouseX > 650 && mouseX <= 700)
                        moveRight = true;
                            if (moveRight == true) {
                        if (mapCurrentX + screenX < (xDimension)) {
                             mapCurrentX -= moveSpeed;
                             contentPane.setLocation(mapCurrentX, mapCurrentY);
                   try {
                        // Stop thread for 20 milliseconds
                        Thread.sleep(20);
                   catch (InterruptedException ex) {
                        // do nothing
                   Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
         }

    I got this when I ran it ^_^;; Gonna try to fix it
    Wrong Thread
    java.lang.Exception: Stack trace
         at java.lang.Thread.dumpStack(Unknown Source)
         at ThreadCheckingRepaintManager.checkThread(ThreadCheckingRepaintManager.java:13)
         at ThreadCheckingRepaintManager.addInvalidComponent(ThreadCheckingRepaintManager.java:6)
         at map.<init>(map.java:74)
         at ClientMain3.init(ClientMain3.java:12)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

  • Memery problem of swing

    I programmed a applet with swing, imbedded in html page. then opened a browser window to run it, everything was ok but the memory used was increasing with every clicking the applet. Anyone can help me?

    I found out that only the window is not active the memory used goes down.This is the evidence that the garbage collector is running when necessary. So don't worry about it. Once your program uses too much memory (How much does it use anyway?), gc will kick in.
    As your program runs on a computer in your company's hallway, it seems very unlikely there are other processes competing for memory. And I bet the window isn't active all the time day and night. :-)
    If the memory problem concerns you very much, you can optimize your program by using static instances of frequently used objects instead of allocating new ones every time users click.

  • Problems with swing, please help!!!

    im trying to display an image made up of a set of squares.
    i have a JFrame class which has the main method placing a JComponent into its Container using the getContentPane().add method.
    the JComponent class sets up the image using the paintComponent() method
    When i try to run the program all i get is a grey frame.
    Ive looked at other threads in this forum to fix my problem but it doesnt seem to fix it.
    any help is much appreciated.

    import java.awt.*;
    import java.awt.event.*;
    import java.util.EventListener;
    import javax.swing.*;
    import java.applet.*;
    public class Display extends JFrame
         protected DisCanvas canvas;
         protected EventListener listener;
         protected boolean isApplet = false;
         public Display(boolean isApplet)
              this.isApplet = isApplet;
              //setLayout(new BorderLayout());
         //     add(makeCanvas(), BorderLayout.CENTER);
         public Display()
              //this(true);
    canvas = new DisCanvas();
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(canvas, BorderLayout.CENTER);
    this.addWindowListener(new AppCloser());
    this.setSize(300, 300);
    this.setVisible(true);
    this.repaint();
    public static void main(String[] args)
    new Display();
    static class AppCloser extends WindowAdapter
              public void windowClosing(WindowEvent e)
                   System.exit(0);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.image.*;
    public class DisCanvas extends java.awt.Canvas
    Patch[] patchArray = new Patch[100];
    int width = 200;
    int height = 300;
    BufferedImage image;
    Graphics2D g2D;
    public DisCanvas()
    patchArray[0] = new Patch(0, 0, 20, 30); patchArray[10] = new Patch(0, 30, 20, 30);
    patchArray[1] = new Patch(20, 0, 20, 30); patchArray[11] = new Patch(20, 30, 20, 30);
    patchArray[2] = new Patch(40, 0, 20, 30); patchArray[12] = new Patch(40, 30, 20, 30);
    patchArray[3] = new Patch(60, 0, 20, 30); patchArray[13] = new Patch(60, 30, 20, 30);
    patchArray[4] = new Patch(80, 0, 20, 30); patchArray[14] = new Patch(80, 30, 20, 30);
    patchArray[5] = new Patch(100, 0, 20, 30); patchArray[15] = new Patch(100, 30, 20, 30);
    patchArray[6] = new Patch(120, 0, 20, 30); patchArray[16] = new Patch(120, 30, 20, 30);
    patchArray[7] = new Patch(140, 0, 20, 30); patchArray[17] = new Patch(140, 30, 20, 30);
    patchArray[8] = new Patch(160, 0, 20, 30); patchArray[18] = new Patch(160, 30, 20, 30);
    patchArray[9] = new Patch(180, 0, 20, 30); patchArray[19] = new Patch(180, 30, 20, 30);
    patchArray[20] = new Patch(0, 60, 20, 30); patchArray[30] = new Patch(0, 90, 20, 30);
    patchArray[21] = new Patch(20, 60, 20, 30); patchArray[31] = new Patch(20, 90, 20, 30);
    patchArray[22] = new Patch(40, 60, 20, 30); patchArray[32] = new Patch(40, 90, 20, 30);
    patchArray[23] = new Patch(60, 60, 20, 30); patchArray[33] = new Patch(60, 90, 20, 30);
    patchArray[24] = new Patch(80, 60, 20, 30); patchArray[34] = new Patch(80, 90, 20, 30);
    patchArray[25] = new Patch(100, 60, 20, 30); patchArray[35] = new Patch(100, 90, 20, 30);
    patchArray[26] = new Patch(120, 60, 20, 30); patchArray[36] = new Patch(120, 90, 20, 30);
    patchArray[27] = new Patch(140, 60, 20, 30); patchArray[37] = new Patch(140, 90, 20, 30);
    patchArray[28] = new Patch(160, 60, 20, 30); patchArray[38] = new Patch(160, 90, 20, 30);
    patchArray[29] = new Patch(180, 60, 20, 30); patchArray[39] = new Patch(180, 90, 20, 30);
    patchArray[40] = new Patch(0, 120, 20, 30); patchArray[50] = new Patch(0, 150, 20, 30);
    patchArray[41] = new Patch(20, 120, 20, 30); patchArray[51] = new Patch(20, 150, 20, 30);
    patchArray[42] = new Patch(40, 120, 20, 30); patchArray[52] = new Patch(40, 150, 20, 30);
    patchArray[43] = new Patch(60, 120, 20, 30); patchArray[53] = new Patch(60, 150, 20, 30);
    patchArray[44] = new Patch(80, 120, 20, 30); patchArray[54] = new Patch(80, 150, 20, 30);
    patchArray[45] = new Patch(100, 120, 20, 30); patchArray[55] = new Patch(100, 150, 20, 30);
    patchArray[46] = new Patch(120, 120, 20, 30); patchArray[56] = new Patch(120, 150, 20, 30);
    patchArray[47] = new Patch(140, 120, 20, 30); patchArray[57] = new Patch(140, 150, 20, 30);
    patchArray[48] = new Patch(160, 120, 20, 30); patchArray[58] = new Patch(160, 150, 20, 30);
    patchArray[49] = new Patch(180, 120, 20, 30); patchArray[59] = new Patch(180, 150, 20, 30);
    patchArray[60] = new Patch(0, 180, 20, 30); patchArray[70] = new Patch(0, 210, 20, 30);
    patchArray[61] = new Patch(20, 180, 20, 30); patchArray[71] = new Patch(20, 210, 20, 30);
    patchArray[62] = new Patch(40, 180, 20, 30); patchArray[72] = new Patch(40, 210, 20, 30);
    patchArray[63] = new Patch(60, 180, 20, 30); patchArray[73] = new Patch(60, 210, 20, 30);
    patchArray[64] = new Patch(80, 180, 20, 30); patchArray[74] = new Patch(80, 210, 20, 30);
    patchArray[65] = new Patch(100, 180, 20, 30); patchArray[75] = new Patch(100, 210, 20, 30);
    patchArray[66] = new Patch(120, 180, 20, 30); patchArray[76] = new Patch(120, 210, 20, 30);
    patchArray[67] = new Patch(140, 180, 20, 30); patchArray[77] = new Patch(140, 210, 20, 30);
    patchArray[68] = new Patch(160, 180, 20, 30); patchArray[78] = new Patch(160, 210, 20, 30);
    patchArray[69] = new Patch(180, 180, 20, 30); patchArray[79] = new Patch(180, 210, 20, 30);
    patchArray[80] = new Patch(0, 240, 20, 30); patchArray[90] = new Patch(0, 270, 20, 30);
    patchArray[81] = new Patch(20, 240, 20, 30); patchArray[91] = new Patch(20, 270, 20, 30);
    patchArray[82] = new Patch(40, 240, 20, 30); patchArray[92] = new Patch(40, 270, 20, 30);
    patchArray[83] = new Patch(60, 240, 20, 30); patchArray[93] = new Patch(60, 270, 20, 30);
    patchArray[84] = new Patch(80, 240, 20, 30); patchArray[94] = new Patch(80, 270, 20, 30);
    patchArray[85] = new Patch(100, 240, 20, 30); patchArray[95] = new Patch(100, 270, 20, 30);
    patchArray[86] = new Patch(120, 240, 20, 30); patchArray[96] = new Patch(120, 270, 20, 30);
    patchArray[87] = new Patch(140, 240, 20, 30); patchArray[97] = new Patch(140, 270, 20, 30);
    patchArray[88] = new Patch(160, 240, 20, 30); patchArray[98] = new Patch(160, 270, 20, 30);
    patchArray[89] = new Patch(180, 240, 20, 30); patchArray[99] = new Patch(180, 270, 20, 30);
    image = new BufferedImage(width, height,BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2D = image.createGraphics();
    public void paint/*Component*/(Graphics g)
    g = (Graphics2D) g2D;
    super.paint/*Component*/(g);
    for (int i = 0; i == 99; i++)
    //for (int s = 0; s > 5; s++)
    // Color[] colours = new Color[6];
    // colours[0] = Color.blue;
    // colours[1] = Color.red;
    // colours[2] = Color.green;
    // colours[3] = Color.orange;
    // colours[4] = Color.black;
    // colours[5] = Color.white;
    // g2D.setColor(colours[s]);
    g2D.setColor(Color.red);
    g2D.fillRect(patchArray.getX(), patchArray[i].getY(),
    patchArray[i].getWidth(), patchArray[i].getHeight());
    g2D.drawImage(image,0, 0, this);

  • Problems with large textarea in ITS transaction

    We have an ITS template which contains a <textarea>. This is working ok for some text, however most of the time when the user enters their text and clicks save the web page hangs.
    In SM51 I can see the report name and the process running, but it isn't doing anything. It is then using up a huge amount of memory and causing a bottleneck.
    I have put an external breakpoint in the PAI of the report, but the system doesn't get that far. It hangs before running any of the code.
    We have recently upgraded from 46c with an external ITS to ERP6 with the internal ITS. This same transaction was working fine before the upgrade.
    We have checked all the memory parameter settings we can see. The em/global_area_MB is set to 3GB and the text is only a few paragraphs long. Is there another parameter we can change?
    The textarea source code is as follows.
    <textarea cols="95" rows="10" name="ASI:95[]">
    The SM11 trace files produce the following errors.
    X Tue Sep 23 17:42:18 2008                                                                               
    X  *** ERROR => EmActiveData: Invalid Context Handle -1 [emxx.c       2214]                                                        
    X                                                                               
    X Tue Sep 23 17:42:40 2008                                                                               
    X  *** ERROR => EmActiveData: Invalid Context Handle -1 [emxx.c       2214]                                                        
    X                                                                               
    X Tue Sep 23 17:43:25 2008                                                                               
    X        *** ERROR => EgAlloc: MmxMalloc failed (9). see also file 'mm.dump' [egxx.c       521]                                    
    X        *** ERROR => EmIAllocMmResourceEg: EgAlloc(1048576) failed 5 [emxx.c       3210]                                          
    X        *** ERROR => EgAlloc: MmxMalloc failed (9). see also file 'mm.dump' [egxx.c       521]                                    
    X        *** ERROR => EmIAllocMmResourceEg: EgAlloc(1048576) failed 5 [emxx.c       3210]                                          
    W        *** ERROR => ipl_Malloc EmAlloc(512033) returns 7 [itsplmem.c   148]                                                      
    W        *** ERROR => diag: Memory of 512000 bytes allocation failed, increase em/global_area_MB ? [its_rtmem.cp 524]              
    M        ***LOG W0B=> em/global_area_MB& [its_rtmem.cp 525]                                                                        
    W        *** ERROR => Memory allocation failed, size=512000 [its_rtmem.cp 887]                                                     
    W                                                                               
    W Tue Sep 23 17:43:27 2008                                                                               
    W        *** ERROR => xgdk: CtxtAllocSpace, MmxMalloc failed [w3xxctxt.c   1481]                                                   
    X        *** ERROR => EgAlloc: MmxMalloc failed (9). see also file 'mm.dump' [egxx.c       521]                                    
    X        *** ERROR => EmIAllocMmResourceEg: EgAlloc(1048576) failed 5 [emxx.c       3210]                                          
    X        *** ERROR => EgAlloc: MmxMalloc failed (9). see also file 'mm.dump' [egxx.c       521]                                    
    X        *** ERROR => EmIAllocMmResourceEg: EgAlloc(1048576) failed 5 [emxx.c       3210]                                          
    W        *** ERROR => ipl_Malloc EmAlloc(512033) returns 7 [itsplmem.c   148]                                                      
    W        *** ERROR => diag: Memory of 512000 bytes allocation failed, increase em/global_area_MB ? [its_rtmem.cp 524]              
    M        ***LOG W0B=> em/global_area_MB& [its_rtmem.cp 525]                                                                        
    W        *** ERROR => Memory allocation failed, size=512000 [its_rtmem.cp 887]                                                     
    W                                                                               
    It then repeats this section every couple of seconds until the session is terminated via SM51.
    W Tue Sep 23 17:43:27 2008                                                                               
    W        *** ERROR => xgdk: CtxtAllocSpace, MmxMalloc failed [w3xxctxt.c   1481]                                                   
    X        *** ERROR => EgAlloc: MmxMalloc failed (9). see also file 'mm.dump' [egxx.c       521]                                    
    X        *** ERROR => EmIAllocMmResourceEg: EgAlloc(1048576) failed 5 [emxx.c       3210]                                          
    X        *** ERROR => EgAlloc: MmxMalloc failed (9). see also file 'mm.dump' [egxx.c       521]                                    
    X        *** ERROR => EmIAllocMmResourceEg: EgAlloc(1048576) failed 5 [emxx.c       3210]                                          
    W        *** ERROR => ipl_Malloc EmAlloc(512033) returns 7 [itsplmem.c   148]                                                      
    W        *** ERROR => diag: Memory of 512000 bytes allocation failed, increase em/global_area_MB ? [its_rtmem.cp 524]              
    M        ***LOG W0B=> em/global_area_MB& [its_rtmem.cp 525]                                                                        
    W        *** ERROR => Memory allocation failed, size=512000 [its_rtmem.cp 887]                                                     
    We have recently installed patch 178.
    The problem is happening in IE and Firefox.
    Is anyone able to help us resolve this issue?
    Many thanks
    Karen

    The simplest solution is either to reduce the system load by stopping unnecessary processes or to increase the scope of the swap
    When you set the memory for the integrated ITS (1), you determine the maximum amount of memory that the integrated ITS may consume.
    When you set the number of slots in the template cache (2), you determine how much of this memory is to be used for the preparsed templates.
    Changing the slots in the template cache has the following effect:
    If you increase the number of slots, the template cache becomes larger. The performance of the ITS applications improves. However, there is less memory for ITS sessions, and you can run fewer ITS sessions in parallel.
    If you reduce the number of the slots, the template cache becomes smaller. The applications take more time to run because templates have to be parsed again and again. There is more memory for ITS sessions, and you can run more ITS sessions in parallel.
    If there is sufficient memory, set the number of slots so that there are always empty slots in the template cache. There is then no displacement in the template cache. (Best performance)

  • Adobe acrobat causing repaint problems in swing app

    Hello,
    I am launching an external PDF browser from my swing desktop application using Process.exec(String[],String[],File) .
    The problem is that once the adobe screen is visible (on top of my application's frame), moving it around causes the contents of my own frame to become "greyed out". The frame does not repaint itself until adobe is closed.
    I have searched for similar problems on this forum with no success. Any ideas would be appreciated.
    Thanks.

    That is usally an indicator that you have thread locked the Event thread.
    Are you by chance calling
    process.waitFor() on the returned process?

  • Resolution problems with Swing, MigLayout, and Substance.

    I've got some testers trying out my application on various systems. One computer is a Dell Mini and it is giving me some trouble with resolution. I am using MigLayout as the layout manager for every JPanel and for everything. I am also using Substance L & F. I thought this would be all I need to do to keep my application resolution independent. It appears that I have too many rows. The extra rows are getting cut off.
    I''ve edited my code and posted the relavent part of my code in the following post.

    import java.awt.Color;
    import java.awt.EventQueue;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.text.NumberFormat;
    import javax.swing.*;
    import org.jvnet.substance.skin.SubstanceCremeCoffeeLookAndFeel;
    import net.miginfocom.swing.MigLayout;
    public class SiteInfoPanel extends JPanel{
        private JTextField swisNumber;
        private JTextField siteName;
        private JFormattedTextField lat;
        private JFormattedTextField lon;
        private JFormattedTextField openYear;
        private JFormattedTextField closeYear;
        private JFormattedTextField waste;
        private JFormattedTextField footprint;
        private JButton searchName;
        private JButton searchSWIS;
        private JLabel or1;
        private JLabel siteInfo;
        private JLabel swisNumberL;
        private JLabel nameL;
        private JLabel county;
        private JLabel latL;
        private JLabel lonL;
        private JLabel openYearL;
        private JLabel closeYearL;
        private JLabel wasteL;
        private JLabel footprintL;
        private JLabel searchBy;
        private JSeparator sep1;
        private JSeparator sep2;
        public SiteInfoPanel(){
            initComponents();
        private void initComponents(){
            swisNumber = new JTextField();
            swisNumber.setHorizontalAlignment(JTextField.CENTER);
            swisNumber.setColumns(25);
            siteName = new JTextField();
            siteName.setHorizontalAlignment(JTextField.CENTER);
            siteName.setColumns(40);
            NumberFormat yr = NumberFormat.getInstance();
            yr.setGroupingUsed(false);
            yr.setMaximumIntegerDigits(4);
            yr.setMaximumFractionDigits(0);
            NumberFormat loc = NumberFormat.getInstance();
            loc.setGroupingUsed(false);
            loc.setMaximumIntegerDigits(3);
            loc.setMaximumFractionDigits(2);
            NumberFormat rest = NumberFormat.getInstance();
            rest.setGroupingUsed(false);
            rest.setMaximumFractionDigits(2);
            rest.setMaximumIntegerDigits(9);
            lat = new JFormattedTextField(loc);
            lat.setColumns(8);
            lon = new JFormattedTextField(loc);
            lon.setColumns(8);
            openYear = new JFormattedTextField(yr);
            openYear.setColumns(4);
            closeYear = new JFormattedTextField(yr);
            closeYear.setColumns(4);
            waste = new JFormattedTextField(rest);
            waste.setColumns(10);
            footprint = new JFormattedTextField(rest);
            footprint.setColumns(10);
            swisNumberL = new JLabel("SWIS number:");
            nameL = new JLabel("Site name:");
            county = new JLabel();
            latL = new JLabel("Site Latitude: ");
            lonL = new JLabel("Site Longitude: ");
            openYearL = new JLabel("Opening Year");
            closeYearL = new JLabel("Closing Year");
            wasteL = new JLabel("Waste in place (tons)");
            footprintL = new JLabel("Site footprint (acres)");
            or1 = new JLabel("OR");
            siteInfo = new JLabel("Site Info:");
            siteInfo.setForeground(Color.blue);
            searchBy = new JLabel("Search for site by: ");
            searchBy.setForeground(Color.blue);
            sep1 = new JSeparator();
            sep2 = new JSeparator();
            searchName = new JButton("Search by name");
            searchSWIS = new JButton("Search by SWIS #");
            buildComponents();
        private void buildComponents(){
            this.setLayout(new MigLayout("wrap 4", "[grow]", "[]25[]"));
            this.add(searchBy, "span 4, split 2");
            this.add(sep1, "span 3, growx");
            this.add(swisNumberL, "right");
            this.add(swisNumber, "span 2, center");
            this.add(searchSWIS, "wrap");
            this.add(or1,"skip 3");
            this.add(nameL, "right");
            this.add(siteName,"span 2, center");
            this.add(searchName);
            this.add(county,"skip 1, right");
            this.add(new JLabel(" County"), "wrap");
            this.add(siteInfo, "span 5, split 2");
            this.add(sep2,"span 3, growx");
            this.add(latL,"right");
            this.add(lat, "wrap");
            this.add(lonL, "right");
            this.add(lon, "wrap");
            this.add(footprintL, "right");
            this.add(footprint, "wrap");
            this.add(new JLabel("BLAH"), "span 2, split 2");
            this.add(new JSeparator(), "growx, wrap");
            this.add(new JCheckBox("BLAH"), "center, wrap");
            this.add(openYearL,"right");
            this.add(openYear, "wrap");
            this.add(closeYearL, "right");
            this.add(closeYear, "wrap");
            this.add(wasteL,"right");
            this.add(waste, " wrap");
            this.setVisible(true);
        public static void main(String args[]){
            try {
                UIManager.setLookAndFeel(new SubstanceCremeCoffeeLookAndFeel());
            } catch (UnsupportedLookAndFeelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            EventQueue.invokeLater(new Runnable(){
                @Override
                public void run() {
                    JFrame f = new JFrame();
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    f.getContentPane().add(new SiteInfoPanel());
                    f.pack();
                    f.setVisible(true);
    }<!--
    @page { margin: 0.79in }
    P { margin-bottom: 0.08in }
    -->

Maybe you are looking for