A problem with JTextArea.write()

hi, I'm writting some code about reading content of a TextArea by use the method JTextArea.write().
when the content is short, that will be ok, but the content is too long, my thread seems to be dead. and NetBeans's debuger shows nothing, just unresponse.
can someone to point out my problem in the code below?
textSource.write(bfw); //textSource is extends from JTextArea, when content in it is too large, dead here
private void output2textResult() {
        Runnable myThread = new Runnable() {
            public void run() {
                // component.doSomething();
                final String source = txtFldSource.getText();
                final String destination= txtFldDestination.getText();
                String tmp;
                try{
                    PipedWriter pipOut = new PipedWriter();                  
                    BufferedWriter bfw = new BufferedWriter(pipOut);   //I wrapped the pipOut with the BufferedWrite
                    PipedReader pipIn = new PipedReader(pipOut);
                    BufferedReader bfr= new BufferedReader(pipIn);
//problem line below
                    textSource.write(bfw);   //textSource is extends from JTextArea, when content in it is too large, dead here  
                    while(bfr.ready()){
                        tmp = bfr.readLine();
                        tmp.replaceAll(source, destination);
                        textResult.append(tmp+"\n");
                    bfr.close();
                    pipIn.close();
                    pipOut.close();
                }catch(IOException e){
                    System.out.println(e);
        SwingUtilities.invokeLater(myThread);

This won't work. Pipes are for use between threads. The implication of what you're doing in a single thread is that the pipe is somehow capable of holding the entire source text (which it isn't). In other words you're just trying to buffer it, so you may as well just get all the source text as a String and do your magic on it directly.

Similar Messages

  • Problem with JTextArea or is it my code, Help!!!

    Hi,
    I am going crazy. I am sending a message to a JTextArea and I get some very wierd things happening? I really need help because this is driving me crazy. Please see the following code to see my annotations for the problems. Has anyone else experienced problems with this component?
    Thanks,
    Steve
    // THIS IS THE CLASS THAT HANDLES ALL OF THE WORK
    public class UpdateDataFields implements ActionListener {     // 400
         JTextArea msg;
         JPanel frameForCardPane;
         CardLayout cardPane;
         TestQuestionPanel fromRadio;
         public UpdateDataFields( JTextArea msgout ) {     // 100
              msg = msgout;
          }       // 100
         public void actionPerformed(ActionEvent evt) {     // 200
              String command = evt.getActionCommand();
              String reset = "Test of reset.";
              try{
                   if (command.equals("TestMe")){     // 300
                        msg.append("\nSuccessful");
                        Interface.changeCards();
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
              try{
                   if (command.equals("ButtonA")){     // 300
    // WHEN I CALL BOTH OF THE FOLLOWING METHODS THE DISPLAY WORKS
    // BUT THE CHANGECARDS METHOD DOES NOT WORK.  WHEN I COMMENT OUT
    // THE CALL TO THE DISPLAYMESSAGE METHOD THEN THE CHANGECARDS WORKS
    // FINE.  PLEASE THE INTERFACE CLASS NEXT.
                        Interface.changeCards();
                        Interface.displayMessage("test of xyz");
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
         }     // 200
    }     // 400
    // END OF UPDATEDATAFIELS  END END END
    public class Interface extends JFrame {     // 300
         static JPanel frameForCardPane;
         static CardLayout cardPane;
         static JTextArea msgout;
         TestQuestionPanel radio;
         Interface () {     // 100
              super("This is a JFrame");
            setSize(800, 400);  // width, height
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // set-up card layout
              cardPane = new CardLayout();
              frameForCardPane = new JPanel();     // for CardLayout
              frameForCardPane.setLayout(cardPane);     // set the layout to cardPane = CardLayout
              TestQuestionPanel cardOne = new TestQuestionPanel("ABC", "DEF", msgout, radio);
              TestQuestionPanel cardTwo = new TestQuestionPanel("GHI", "JKL", msgout, radio);
              frameForCardPane.add(cardOne, "first");
              frameForCardPane.add(cardTwo, "second");
              // end set-up card layout
              // set-up main pane
              // declare components
              msgout = new JTextArea( 8, 40 );
              ButtonPanel commandButtons = new ButtonPanel(msgout);
              JPanel pane = new JPanel();
              pane.setLayout(new GridLayout(2, 4, 5, 15));             pane.setBorder(BorderFactory.createEmptyBorder(30, 20, 10, 30));
              pane.add(frameForCardPane);
                 pane.add( new JScrollPane(msgout));
                 pane.add(commandButtons);
              msgout.append("Successful");
              setContentPane(pane);
              setVisible(true);
         }     // 100
    // HERE ARE THE METHODS THAT SHOULD HANDLE THE UPDATING
         static void changeCards() {     // 200
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
         }     // 200
         static void displayMessage(String test) {     // 200
                   String reset = "Test of reset.";
                   String passMessage = test;
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
                   msgout.append("\n"+ test);
         }     // 200
    }     // 300

    Hi,
    I instantiate it in this class. Does that change your opinion or the advice you gave me? Please help!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class CardLayoutQuestionsv2 {
        public static void main(String[] arguments) {
            JFrame frame = new Interface();
            frame.show();
    }

  • Problems with DVD writer

    I recently built a new machine with a P965 Platinum MB.  I put in a Optiarc AD7170 DVD writer.  Even though I was able to install windows XP with it, I immediately had problems once windows XP was up and running.  The MSI utility CD wouldn't run.  Windows explorer would hang up.  I would also get some fatal windows errors.  I replaced the DVD writer with a CD writer that I had laying around and everything was fine. 
    I put the DVD writer in my older machine and it works fine.  I also had a friend try it in his and everything was OK.
    I couldn't find anything on the web about this particular brand.  There was some mentions in this forum about JMicron.  Could there be some incompatibility with the writer and the motherboard or the JMicron controller?

    I have a similar but actually quite different problem.  My p965platinum's BIOS won't even show my IDE drives,  sometimes,  well most of the time..
    OS Name   Microsoft Windows XP Professional
    Version   5.1.2600 Service Pack 3 Build 2600
    OS Manufacturer   Microsoft Corporation
    System Name   
    System Manufacturer   MICRO-STAR INTERNATIONAL CO.,LTD
    System Model   MS-7238
    System Type   X86-based PC
    Processor   x86 Family 15 Model 4 Stepping 1 GenuineIntel ~2999 MHz
    BIOS Version/Date   American Megatrends Inc. V1.8, 12/1/2007
    SMBIOS Version   2.5
    Windows Directory   C:\WINDOWS
    System Directory   C:\WINDOWS\system32
    Boot Device   \Device\HarddiskVolume1
    Locale   United States
    Hardware Abstraction Layer   Version = "5.1.2600.5512 (xpsp.080413-2111)"
    User Name   
    Time Zone   Mountain Daylight Time
    Total Physical Memory   2,048.00 MB (Corsair XMS2 DHX [matched pair] 2 x 2GB DDR2 6400C4DHX cas5) running 5,5,5,18
    Available Physical Memory   1.43 GB
    Total Virtual Memory   2.00 GB
    Available Virtual Memory   1.96 GB
    Page File Space   3.85 GB
    Page File   C:\pagefile.sys
    I have reset the CMOS several times and once in a great while the IDE and the devices,  1 WD60GB HDD and 1 Asus 1814 DVDR/RW,  will show and work.   I have changed out the cables several times and It showed up one time.  I just bought a new cable (24" rnd 80) and that hasn't helped. I have checked the power plugs to the devices and they have power.     I have set the drives from IDE - SATA - etc.   No go.  The DVD's jumper is set to Master and is at the end of the cable,  the HDD is set to Slave  on the middle of the cable. 
    Can't see a correlation but Boot.ini running in PAE mode.
    Could there be something wrong with the board or the BIOS?
    Twice I have done a hard shutdown and it has showed up.  But when I restart or shut it down for the night It won't show when it starts back up??   System Restore does nothing.
    On other old BIOS' I could hit a key to "detect" drives,  but this BIOS has no option for that.  Everything it "Auto".
    Any help would be appreciated

  • Problems with ImageIO.write()

    Well I am finding it very strange with ImageIO.write();
    Consider the following code snippet:
    BufferedImage img=ImageIO.read(new File("fw2.jpg"));
    BufferedImage img1=new BufferedImage(img.getWidth(),img.getHeight(),img.TYPE_INT_ARGB);
    for(int i=0;i<img.getHeight();i++)
    for(int j=0;j<img.getWidth();j++)
    img1.setRGB(j,i,img.getRGB(j,i));
    ImageIO.write(img1,"jpg",new File("fwinv.jpg"));
    So simply I am copying fw2.jpg to fwinv.jpg. fw2.jpg was also created
    using ImageIO.write().
    But the two files are having different pixel values.
    i.e If I read fwinv.jpg again I will get different pixel value that it was written.
    Why is this...Can any one please help me..

    Reading the written images back and displaying them in java works okay. The third image looks okay in RGB but wrong in ARGB when displayed by a native app. For more about this see reply 1 in Color problems and the linked bug report: Some Images written using JPEG Image Writer are not recognized by native applns.
    import java.awt.GridLayout;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class WriteTest {
        private JPanel getContent(BufferedImage src) throws IOException {
            File fileOne = new File("fileOne.jpg");
            ImageIO.write(src, "jpg", fileOne);
            BufferedImage image1 = ImageIO.read(fileOne);
            BufferedImage image2 = copy(image1);
            JPanel panel = new JPanel(new GridLayout(1,0));
            panel.add(new JLabel(new ImageIcon(src)));
            panel.add(new JLabel(new ImageIcon(image1)));
            panel.add(new JLabel(new ImageIcon(image2)));
            return panel;
        private BufferedImage copy(BufferedImage in) throws IOException {
            int w = in.getWidth();
            int h = in.getHeight();
            int type = BufferedImage.TYPE_INT_ARGB;   // problem in native apps
                       //BufferedImage.TYPE_INT_RGB;  // this one works okay
            BufferedImage out = new BufferedImage(w, h, type);
            for(int y = 0; y < h; y++) {
                for(int x = 0; x < w; x++) {
                    out.setRGB(x, y, in.getRGB(x, y));
            File fileTwo = new File("fileTwo.jpg");
            ImageIO.write(out, "jpg", fileTwo);
            return ImageIO.read(fileTwo);
        public static void main(String[] args) throws IOException {
            BufferedImage image = ImageIO.read(new File("images/cougar.jpg"));
            WriteTest test = new WriteTest();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test.getContent(image));
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Problem with CD writer interaction!!!!

    Hi! I'm trying to write a program that will interact with any CD writer which means the program supposed to be capable of burning data on a CD. Is it possible to interact with CD writer in Java? If it is can anyone point me to a online resource where it is explained clearly or can anyone explain it to me in plain English?
    Thanks in advance.
    --DM777                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    To burn CD's, you have to interact with the CD-burner on a pretty low level (hardware level). Java doesn't support this by default.
    There may be 3rd-party libraries (probably based on JNI), which give you burner support, but I don't know of one.
    Cheers,
    --Arnout                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Problem with JTextArea

    Hi all,
    I am having a class which extends JTextArea. I press backspace and I check for some condition in KeyReleased event. If the condition is true I am setting the JTextArea with the old text(retainText). What happens here is that first the backspace entered by me is reflecting on the screen and then only the new text (retainText) is set. This causes a flickering on the text area. My requirement is that this should not happen.
    Is there any way to avoid this .
    or else Is there any way to cancel this event ( say i enter backspace and if the condition becomes true in the KeyReleased event, I should stop this event. Can any body please help me ASAP. Thanks!!!
    I ve attached the code also
    package com.bankofny.iic.client.component;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    import com.bankofny.iic.client.instruction.viewer.TradeDetailForm;
    import com.bankofny.iic.common.util.StringFormatter;
    public class IicTextAreaSwift extends JTextArea implements FocusListener, KeyListener
        // IicTextAreaSwift Method
         private int DescCharWidth = 0;
        private int DescCharHeight =0;
         private String retainText; //retain always the latest text
         private int KeyCode;
         private String KeyText="";
        public IicTextAreaSwift(int _rows, int _columns, boolean scrollPane)
            super(_rows, _columns + 1);
            setDisabledTextColor(Color.gray);
                rows            = _rows;
            columns         = _columns;
            setRows(_rows);
            maxTextAllowed  = _rows * _columns;
            setBorder(new BevelBorder(BevelBorder.LOWERED));
            setLineWrap(true);
            setWrapStyleWord(true);
            Font fixedFont = new Font("Courier", Font.PLAIN, 12);
            setFont(fixedFont);
            FontMetrics fm = getFontMetrics(fixedFont);
            DescCharWidth = fm.charWidth('W') * (_columns + 1);
          //  DescCharHeight = fm.getHeight() * 4 ;
               DescCharHeight =  DEFAULT_LABEL_HEIGHT * 3;
            setPreferredSize(new Dimension(DescCharWidth, DescCharHeight));
            // setSize(new Dimension(DescCharWidth, DescCharHeight));
            addKeyListener(this);
            addFocusListener(this);
            fixTAB();
        public IicTextAreaSwift(int _rows, int _columns)
              super(_rows, _columns);
              // HA this constructor is for this field not in a scroll pane
              setDisabledTextColor(Color.gray);
              rows            = _rows;
              columns         = _columns;
              setRows(_rows);
              maxTextAllowed  = _rows * _columns;
              setBorder(new BevelBorder(BevelBorder.LOWERED));
              setLineWrap(true);
              setWrapStyleWord(true);
              Font fixedFont = new Font("Courier", Font.PLAIN, 12);
              setFont(fixedFont);
              FontMetrics fm = getFontMetrics(fixedFont);
              DescCharWidth = fm.charWidth('W') * (_columns + 1);
             //  DescCharHeight = fm.getHeight() * 4 ;
              DescCharHeight =  DEFAULT_LABEL_HEIGHT * 3;
              setPreferredSize(new Dimension(DescCharWidth, DescCharHeight));
              // setSize(new Dimension(DescCharWidth, DescCharHeight));
              addKeyListener(this);
              addFocusListener(this);
              fixTAB();
        public Dimension getDimen()
              return new Dimension(     DescCharWidth, DescCharHeight);
         public void showKeys(JComponent component)
              // List keystrokes in the WHEN_FOCUSED input map of the component
              InputMap map = component.getInputMap(JComponent.WHEN_FOCUSED);
              printInputMap(map,"WHEN_FOCUSED");
              // List keystrokes in the WHEN_ANCESTOR_OF_FOCUSED_COMPONENT input map of the component
              map = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
              printInputMap(map,"WHEN_ANCESTOR_OF_FOCUSED_COMPONENT");
              //list(map, map.keys());
              // List keystrokes in all related input maps
              //list(map, map.allKeys());
              // List keystrokes in the WHEN_IN_FOCUSED_WINDOW input map of the component
              map = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
              printInputMap(map,"WHEN_IN_FOCUSED_WINDOW");
              printActionMap( getActionMap() , "JTextArea");
              //list(map, map.keys());
              // List keystrokes in all related input maps
            // list(map, map.allKeys());
         public void fixTAB()
              Set newForwardKeys = new HashSet ();
              newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0, false));
              this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys);
              Set newBackwardKeys = new HashSet ();
              newBackwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK, false));
              this.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newBackwardKeys);
              Set forwardKeys = this.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    //          System.out.println ("Desktop forward focus traversal keys: " + forwardKeys);
              Set backwardKeys = this.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    //          System.out.println ("Desktop backward focus traversal keys: " + backwardKeys);
             this.setFocusTraversalKeysEnabled(true);
         public static void printActionMap(ActionMap actionMap, String who)
         {     //     System.out.println("Action map for " + who + ":");
              Object[] keys = actionMap.allKeys();
              if (keys != null)
                   for (int i = 0; i < keys.length; i++)
                        Object key = keys;
                        Action targetAction = actionMap.get(key);
                   //     System.out.println("\tName: <" + key + ">, action: " + targetAction.getClass().getName());
         public static void printInputMap(InputMap inputMap, String heading)
              //System.out.println("\n" + heading + ":");
              KeyStroke[] keys = inputMap.allKeys();
              if (keys != null)
                   for (int i = 0; i < keys.length; i++)
                        KeyStroke key = keys[i];
                        Object actionName = inputMap.get(key);
                   //     System.out.println("\tKey: <" + key + ">, action name: " + actionName);
    public void paste()
    public void focusGained(java.awt.event.FocusEvent event)
              //System.out.println("Hman " + event.paramString());
         if(event.getOppositeComponent() != null)
              if(event.getOppositeComponent().getParent() != null)
                   if (findRoot(event.getOppositeComponent()) != null && findRoot(this) != null)
                        if ( isEnabled() && findRoot(event.getOppositeComponent()) == findRoot(this))
                        selectAll();
         public Component findRoot(Component _cc)
              while (_cc.getParent() != null)
                   cc = cc.getParent();
                   //System.out.println("Parent:" + _cc);
                   if (_cc instanceof TradeDetailForm)
                   return _cc;
              return null;
    public void focusLost(java.awt.event.FocusEvent event)
         Begin Nirmal 1: Requirements 3.1 issues.
         To fix: getValue() method never returns more than the rows.
         New method added to ensure user entered text never goes beyond Rows
    * Method to ensure the getValue() never returns more than the rows.
    * will return -1 if the rows are out of range
    * @param KeyEvent
    * @return int
    public int ensureNotBeyondRows(KeyEvent e)
              String[] s = getValue();
              if (s==null)
                   return 0;
              if (s.length>rows)
                   setText(retainText);
                   return -1;
              String str=getText();
              insert(e.getKeyChar()+"", getCaretPosition());
              s = getValue();
              setText(str);
              if (s.length>rows)
                   setText(retainText);
                   return -1;
              return 0;
         End Nirmal 1:
    // main Method
    // processComponentKeyEvent Method
    public void keyTyped(KeyEvent e)
         /* Naga */
              System.out.println("inside keyTyped");
              System.out.println("e.getKeyChar() " + KeyEvent.getKeyText(e.getKeyCode()));
         /*try
                   java.lang.Thread.sleep(2000);
              catch(InterruptedException ie)
         try {
    int curPos2 = getCaretPosition();
    int curLine2 = getLineOfOffset(curPos2);
    //System.out.println( "curline:" + curLine2 + " of " + rows);
    char[] tmp = {e.getKeyChar()};
    int curPos1 = getCaretPosition();
    int line1 = getLineOfOffset(curPos1) ;
    int startOfLine = getLineStartOffset(line1) ;
    if( curPos1 == startOfLine && line1 > 0)
    if ((tmp[0] == ':') || (tmp[0] == '-' )){
    // System.out.println("hman3");
    e.consume();
    return;
                   Begin Nirmal 2: Requirements 3.1 issues.
                   To fix: getValue() method never returns more than the rows.
                   New method added to ensure user entered text never goes beyond Rows
                   if (!isArrowKey(e) &&
                        (e.paramString().indexOf("Enter") == -1 ) &&
                        !isBackspaceKey(e)) {
                             int maxLimitFlg=ensureNotBeyondRows(e);
                             setCaretPosition(curPos2);
                             if (maxLimitFlg == -1)
                                  e.consume();
                                  return;
                   End Nirmal 2:
    // System.out.println("e.paramString()" + e.paramString());
    // System.out.println("place 2 " + e.paramString());
    if (!(StringFormatter.isValidSwift(tmp[0])) && !(functionKey(e)) && notMoveForward(e))
    // System.out.println("hman2 isaction" + e.isActionKey());
    // System.out.println("KeyTyped" + e.getKeyChar()+ e.getKeyText(e.getKeyCode()) + "/keycode" + e.getKeyCode() + "/modifiers" + e.getModifiers() );
    e.consume();
    return;
    int curPosInLine = -1;
    int firstPos = -1;
    if (getText().length() < maxTextAllowed ||
    (KeyCode == KeyEvent.VK_UP || KeyCode == KeyEvent.VK_BACK_SPACE))
    int curPos = getCaretPosition();
    if (!(functionKey(e)))
    e.setKeyChar( (new String( tmp ).toUpperCase()).toCharArray()[0]);
    curPos2 = getCaretPosition();
    curLine2 = getLineOfOffset(curPos2);
    //System.out.println( "curline:" + curLine2 + " of " + rows);
    if (curLine2 + 1 >= rows &&
    (KeyCode == KeyEvent.VK_ENTER ||
    KeyCode == KeyEvent.VK_DOWN) )
    // System.out.println("hman1");
    e.consume();
    return;
    else {
    String oldText = getText();
    // super.processKeyEvent(e);
    if (getNumberOfLines(getLineCount()) == -1 && !(functionKey(e)))
    setText(oldText);
    invalidate();
    setCaretPosition(curPos);
    } } catch (javax.swing.text.BadLocationException evt) {
    System.out.println("Bad Location Exception in processKeyEvent");
    public void keyPressed(KeyEvent e){
              //System.out.println("keyPressed" + e.getKeyCode()+ e.getKeyText(e.getKeyCode()));
                   retainText = getText();//retain always the latest text
                   /* Naga */
                   //System.out.println("retainText " + retainText);
                   System.out.println("inside keyPressed");
                   System.out.println("e.getKeyChar() " + KeyEvent.getKeyText(e.getKeyCode()));
                   /*try
                        java.lang.Thread.sleep(2000);
                   catch(InterruptedException ie)
    public void keyReleased(KeyEvent e){
              //System.out.println( "keyReleased" + e.getKeyCode()+ e.getKeyText(e.getKeyCode()));
         String []s = getValue();
         /* Naga */
         System.out.println(" inside keyReleased");
         System.out.println("e.getKeyChar() " + KeyEvent.getKeyText(e.getKeyCode()));
         /*try
              java.lang.Thread.sleep(2000);
         catch(InterruptedException ie)
              /*try
                   System.out.println("s " + s[0]);
                   System.out.println("s " + s[1]);
                   System.out.println("s " + s[2]);
                   System.out.println("s " + s[3]);
              catch(Exception e1)
              //System.out.println("s.length " + s.length);
              //System.out.println("rows " + rows);
              if (s!=null && s.length>rows)
                   System.out.println("setting text");
                   //setText(retainText);
                   invalidate();
         public boolean isTab(KeyEvent e)
              if (e.paramString().indexOf("keyChar=Tab") == -1)
              return false;
              } else
                   return true;
         public boolean keepProcessing(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("keyChar=Backspace") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Left") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Down") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Up") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Delete") != -1 ) { return true; }
              if (e.paramString().indexOf("keyChar=Right") != -1 ) { return true; }
              return false;
         public boolean isArrowKey(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("Left") != -1 ||
                   e.paramString().indexOf("Down") != -1 ||
                   e.paramString().indexOf("Up") != -1 ||
                   e.paramString().indexOf("Right") != -1 )
                   return true;
              return false;
         public boolean isBackspaceKey(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("Backspace") != -1)
                   return true;
              return false;
         public boolean isDeleteKey(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("Delete") != -1)
                   return true;
              return false;
    public boolean notMoveForward(java.awt.event.KeyEvent e)
              if (e.paramString().indexOf("Backspace") == -1 &&
              e.paramString().indexOf("Left") == -1 &&
              // e.paramString().indexOf("keyText=Down") == -1 &&
              e.paramString().indexOf("Up") == -1 &&
              e.paramString().indexOf("Delete") == -1 ) { return true; }
              return false;
    // processKeyEvent Method
    public void processKeyEvent(java.awt.event.KeyEvent e)
    //     System.out.println( "processKeyEvent");
         /* Naga */
         System.out.println(" inside processKeyEvent");
         System.out.println("e.getKeyChar() " + KeyEvent.getKeyText(e.getKeyCode()));
                   if (e.paramString().indexOf("KEY_PRESSED") != -1) {
                        KeyText=e.paramString();
                   } else {
                        KeyText="";
                   KeyCode=e.getKeyCode();
    int filledRows = (getText().length()-1)/columns + 1;
    if (KeyCode == KeyEvent.VK_ENTER && filledRows >= rows)
    return;
    try {
                   if (isArrowKey(e) || isBackspaceKey(e) || isDeleteKey(e)) {
                        super.processKeyEvent(e);
                        return;
    int curPos2 = getCaretPosition();
    int curLine2 = getLineOfOffset(curPos2);
    // System.out.println( "curline:" + curLine2 + " of " + rows);
    if (curLine2 + 1 >= rows &&
    (KeyCode == KeyEvent.VK_ENTER ||
    KeyCode == KeyEvent.VK_DOWN) )
                             //System.out.println("hman5");
    e.consume();
    return;
    int curPosInLine = -1;
    int firstPos = -1;
    if (getText().length() < maxTextAllowed)
    int curPos = getCaretPosition();
    curPos2 = getCaretPosition();
    curLine2 = getLineOfOffset(curPos2);
    int curlinepos = getLineStartOffset(curLine2) ;
                   if ( (curLine2 + 1 == rows) && (curPos2 - curlinepos >= getColumns() - 1) && notMoveForward(e))
                        e.consume();
    return;
    if ((curLine2 + 1 >= rows &&
    (KeyCode == KeyEvent.VK_ENTER ||
    KeyCode == KeyEvent.VK_DOWN) ))
    // System.out.println("hman6");
    e.consume();
    return;
    } else {
    String oldText = getText();
    // System.out.println("hman7");
    super.processKeyEvent(e);
    if (getNumberOfLines(getLineCount()) == -1 && !(functionKey(e)))
    // System.out.println("hman8");
    setText(oldText);
    invalidate();
    setCaretPosition(curPos);
    } } catch (javax.swing.text.BadLocationException evt) {
    System.out.println("Bad Location Exception in processKeyEvent");
    // processFunctionalKeys Method
    public boolean processFunctionalKeys(java.awt.event.KeyEvent e)
    // System.out.println( "processFunctionalKeys");
    if (KeyCode == KeyEvent.VK_BACK_SPACE ||
    KeyCode == KeyEvent.VK_ESCAPE ||
    KeyCode == KeyEvent.VK_PAGE_UP ||
    KeyCode == KeyEvent.VK_PAGE_DOWN ||
    KeyCode == KeyEvent.VK_END ||
    KeyCode == KeyEvent.VK_HOME ||
    KeyCode == KeyEvent.VK_LEFT ||
    KeyCode == KeyEvent.VK_UP ||
    KeyCode == KeyEvent.VK_RIGHT ||
    KeyCode == KeyEvent.VK_DOWN ||
    KeyCode == KeyEvent.VK_DELETE
    //System.out.println("Process the KEY getkey:" + e.getKeyChar() + "/getcode:" + e.getKeyCode());
    super.processKeyEvent(e);
    return true;
    else
    return false;
    public boolean functionKey(java.awt.event.KeyEvent e)
    // System.out.println( "functionKey");
    if (KeyCode == KeyEvent.VK_BACK_SPACE ||
    KeyCode == KeyEvent.VK_ESCAPE ||
    KeyCode == KeyEvent.VK_PAGE_UP ||
    KeyCode == KeyEvent.VK_PAGE_DOWN ||
    KeyCode == KeyEvent.VK_END ||
    KeyCode == KeyEvent.VK_HOME ||
    KeyCode == KeyEvent.VK_LEFT ||
    KeyCode == KeyEvent.VK_UP ||
    KeyCode == KeyEvent.VK_RIGHT ||
    KeyCode == KeyEvent.VK_DOWN ||
    KeyCode == KeyEvent.VK_DELETE
    //System.out.println("Process the KEY getkey:" + e.getKeyChar() + "/getcode:" + e.getKeyCode());
    //super.processKeyEvent(e);
    return true;
    else
    return false;
    // getLineCount Method - Returns -1 if number of lines is not between 1 to 4.
    /* This method return -1 if number of lines is not between 1 to 4.
    Pass in getLineCount() to get number of lines for all elements.
    JTextArea separates elements by new line character.
    BnyTextArea treats each row as a line.
    public int getNumberOfLines(int elementCount)
    int lineCount = 0;
    int startPos = 0;
    int endPos = 0;
    for (int i = 0; i <= elementCount - 1; i++) {
    lineCount = lineCount + getLineCountOfElement(i);
    if (lineCount == -1 || lineCount > rows) {
    lineCount = -1;
    break;
    return lineCount;
    // getSpacePos Method - this method finds the first position of space found.
    public int getSpacePos(int pos)
              Begin Nirmal 3: Requirements 3.1 issues.
              Modified the end limit from 0 to pos-columns,
              so that to avoid the return index value from previous lines
              int endLimit=pos-columns;
              if (endLimit<0) {
                   endLimit=pos;
    for (int i = pos; i > endLimit; i--) {
    if (getText().charAt(i) == ' ' || getText().charAt(i) == '\n') { // 11/14/03 Eaten treat \n as space
                        return i;
    return -1;
              End Nirmal 3:
    // getLineCountOfElement Method - returns -1 if number of lines is not between 1 to 4.
    public int getLineCountOfElement(int line)
    int lineCount = 1;
    try {
    int startPos = getLineStartOffset(line) ;
    int endPos = getLineEndOffset(line) ;
    if (moreThanNumOfColumns(startPos, endPos)) {
    lineCount = 2;
    startPos = getSpacePos(startPos+columns);
    if (startPos != -1 && moreThanNumOfColumns(startPos+1,endPos)) {
    lineCount = 3;
    startPos = getSpacePos(startPos+columns);
    if (startPos != -1 && moreThanNumOfColumns(startPos+1,endPos)) {
    lineCount = 4;
    startPos = getSpacePos(startPos+columns);
    if (startPos != -1 && moreThanNumOfColumns(startPos+1,endPos)) {
    return -1;
    } catch (javax.swing.text.BadLocationException e) {
    System.out.println("Bad Location Exception in getLineCountOfElement");
    return lineCount;
    // moreThanNumOfColumns Method
    public boolean moreThanNumOfColumns(int startPos, int endPos)
    if ((endPos - startPos) > (columns + 1))
    return true;
    else
    return false;
    // getNewLineCount Method
    public int getNewLineCount()
    int count = 0;
    boolean rc = true;
    int pos = getText().indexOf(KeyEvent.VK_ENTER, 0);
    if (pos == -1)
    rc = false;
    else
    count++;
    while (rc) {
    pos = getText().indexOf(KeyEvent.VK_ENTER, pos+1);
    if (pos == -1)
    rc = false;
    else
    count++;
    return count;
    // getValue Method
    public String[] getValue()
    // System.out.println(getText());
    int lines = getLineCount();
    int spacePos = 0;
    String str = new String();
    Vector strings = new Vector();
    boolean newLine=true;
    /*Nirmal : this boolean is to add the empty only in new line.
    To avoid those lines which end with \n
    if (getDocument().getLength() > 0) {
    for (int i = 0; i < lines; i++) {
                        newLine=true;
    try {
    int startPos = getLineStartOffset(i) ;
    int endPos = getLineEndOffset(i) + 1;
    /* Naga */
    //System.out.println("startPos " + startPos);
    //System.out.println("endPos " + endPos);
    //System.out.println(i + "HHMAN startPos = " + getLineStartOffset(i));
    //System.out.println(i + "HHMAN endPos = " + getLineEndOffset(i));
    while (moreThanNumOfColumns(startPos,endPos)) {
                                  newLine=false;
    int tempEndPos = 0;
    tempEndPos = startPos + columns;
    System.out.println("tempEndPos " + tempEndPos + " columns " + columns);
    spacePos = getSpacePos(tempEndPos);
    if (spacePos == -1) {
    if (startPos >= getDocument().getLength())
    break;
    else {
    if (tempEndPos >= getDocument().getLength())
    spacePos = getDocument().getLength();
    else {
    spacePos = startPos + columns;
    str = getText().substring(startPos,spacePos);
    if (!(str.trim().equals(""))) {
                                       strings.addElement(str.trim());
    startPos = spacePos;
                             if (startPos < endPos) {
         str = getText().substring(startPos,endPos - 1).trim();
         if(str!=null) {
              if(str.trim().length()>0) {
                                            strings.addElement(str);
                                            continue;
                                       } else {
                                            if(newLine) {
                                                 strings.addElement(str);
    /*Nirmal commented the below lines to fix existing issue
    of adding even empty lines entered in textbox */
    //if ((str==null) || (str.length()==0)) continue;
    //if (!(str.trim().equals(""))) strings.addElement(str);
    } catch (javax.swing.text.BadLocationException e) {
    System.out.println("Bad Location Exception in getValue");
    String[] strs = new String[strings.size()];
    strings.copyInto(strs);
    return strs;
    } else
    return null;
         public void clear() {
    setText("");
    // invalidate();
    // repaint();
    // fixTAB();
    public int getColumnsX()
    if (columnLimits != null)
    int curPos = getCaretPosition();
    //System.out.println("getCaretPosition()" + curPos);
    if (curPos > 0)
    for (int i = 0;i < columnLimits.length;i++)
    curPos = curPos - columnLimits[i];
    if (curPos < 1)
    //System.out.println("getNumberOfLines(curElem)" + i);
    return columnLimits[i];
    } else
    return columns;
    return 0;
         public void setRowLimitX(int rows,int columns)
    maxTextAllowed = rows * columns;
    setRows(_rows);
    rows = _rows;
    columns = _columns;
    setFont(fixedFont);
    setBorder(new BevelBorder(BevelBorder.LOWERED));
    setLineWrap(true);
    setWrapStyleWord(true);
    Font fixedFont = new Font("Courier", Font.PLAIN, 12);
    FontMetrics fm = getFontMetrics(fixedFont);
    int width = fm.charWidth('W') * (35 + 1);
    int height = DEFAULT_LABEL_HEIGHT * 3 ;
    setPreferredSize(new Dimension(width, height));
    public void setEditable(boolean editable)
    super.setEditable(editable);
    super.setEnabled(editable);
    setFocusable(editable);
    if (editable)
    setForeground(Color.black);
    else
    setForeground(Color.gray);
    fixTAB();
    // add your data members here
    // add your data members here
    private int rows = 0;
    private int columns = 0;
    private int[] columnLimits = null;
    private int maxTextAllowed = 0;
    private Font fixedFont = new Font("Courier", Font.PLAIN, 12);
    public final static int LEFT_LABEL_WIDTH = 100;
         public final static int DEFAULT_LABEL_HEIGHT = 20;

    You posted way too much code. 90% of the code is not related to the "backspace" problem. We want compileable and executable code, but only that code that is relevant to the problem.
    Anyway, instead of handling KeyEvents you should read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to Use Key Bindings for the recommended approach.
    Also you may want to check out this posting which has some information on the backspace KeyStroke:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=566748

  • Problem with ImageIO.write

    Hello I am trying to write to file. Here is my code
        try
          File file = new File("C://images//queryX.gif");
        if (file.exists())
            {file.delete();}
          ImageIO.write(bi_new, "GIF", file);  // bi_new is my bufferedImage
        catch (IOException e)
          e.printStackTrace();
        }The file is being created but it is blank. The buffered image is fine because i am having it displayed to screen with an imageicon on a Jlabel.
    Any ideas why the file is blank?
    Cheers.

    The likely problem is that an encoder can not be found.
    First check the return value from the ImageIO.write() method. If it is false it means that an appropriate
    encoder could not be found. (This is quite likely as GIF encoders have some patenting problems and
    Im not sure if SUN has included a GIF encoder.
    Also it should not be necessary to delete the file if it already exists as the ImageIO.write method will
    overwrite it anyway.
    matfud

  • Problem with posting write-ups in ABZU

    Hello,
    May I ask for your help on my concern about transaction ABZU? My asset was capitalized on 31.03.2009 and it has depreciated until last month. I would like to delete this asset because it should not have been recognized as ana sset, so my first procedure would be to derecognize the depreciated that was posted.
    If I use transaction ABZU and use transaction type 700, I encounter an error that says "You cannot post write-ups". The long text explains that "None of the areas to be posted in accordance with the transaction type entered manages one of the depreciation types entered or cumulative values.".
    If I use transaction type 710, I encounter the same error, but the long text says " According to the transaction type, you have to post to area 01. However, in this area, there is either no accumulated depreciation or the write-up depreciation type(s) are not managed in this area.".
    I checked transaction OABU, and I could see that the depreciations areas allow unplanned depreciations. I cehcked the asset reports and the asset explorer and I can see that it contains accumulated depreciation.
    What could be the reason for the error? Could it be some some settings in other customizing transaction other than OABU?
    Thanks in advance for your advice.
    Regards,
    Peter

    Hi peter
    In the previous post you have mentioned that Depreciation is being Run from March - June.
    iey i said 4 months.
    Pass a JV means you post a document Crediting this Asset and Debitting any AUC(or any Expense G/L Account) for the Acquisition Amount.
    After that you go and check in AW01N -->Asset Explorer, system will write the the Adjustment entries in all the periods of the useful life.
    you then reduce the useful life for 5 months,then you will see the Total of the Depreciation posted for 4 months(it will be positive amount).
    why 5months is 4months already Depreciation posted and 1month for running the Adjustment Amount(which is positive so that G/L Account Balances will also be adjusted).
    You first try this scenario in test environment, you will be able to know clearly.
    Hope you understand.
    Regards
    Venkat

  • Problem with JTextArea wanting to resize itself

    First, here is a program that will create the situation in which this error occurs:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.BoxLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    public class Example extends JFrame
        private final String TITLE       = "Example";
        private final int    WIDTH       = 640;
        private final int    HEIGHT      = 480;
        private JMenuBar     menuBar     = new JMenuBar();
        private JMenu        modeMenu    = new JMenu( "Mode" );
        private JMenuItem    mode1       = new JMenuItem( "Mode 1" );
        private JMenuItem    mode2       = new JMenuItem( "Mode 2" );
        private JTextArea    textArea1   = new JTextArea();
        private JTextArea    textArea2   = new JTextArea();
        private JScrollPane  scrollPane1 = new JScrollPane( textArea1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
        private JScrollPane  scrollPane2 = new JScrollPane( textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
        private JPanel       everything  = new JPanel( new BorderLayout() );
        private JPanel       modeOptions = new JPanel();
        private int          modeInt     = 1;
        public Example ()
            setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            setSize( WIDTH, HEIGHT );
            setLocation( 100, 100 );
            setResizable( true );
            mode1.addActionListener( new ActionListener()
                public void actionPerformed ( ActionEvent e )
                    modeInt = 1;
                    updateModeOptions();
            mode2.addActionListener( new ActionListener()
                public void actionPerformed ( ActionEvent e )
                    modeInt = 2;
                    updateModeOptions();
            modeMenu.add( mode1 );
            modeMenu.add( mode2 );
            menuBar.add( modeMenu );
            setJMenuBar( menuBar );
            updateModeOptions();
            initializeLayout();
        private void updateModeOptions ()
            modeOptions.removeAll();
            switch ( modeInt )
                case 1:
                    JLabel text = new JLabel( "Change to Mode 2 to see the text areas shrink." );
                    modeOptions.add( text );
                    setTitle( TITLE + " - " + "Mode 1" );
                    break;
                case 2:
                    JPanel temp = new JPanel();
                    JLabel text = new JLabel( "Text in a JPanel, to show change in text area size." );
                    temp.add( text );
                    modeOptions.add( temp );
                    setTitle( TITLE + " - " + "Mode 2" );
                    break;
                default:
                    break;
            setVisible( true );
        private void initializeLayout ()
            JPanel panel1 = new JPanel( new BorderLayout() );
            JPanel panel2 = new JPanel( new BorderLayout() );
            JPanel everythingCenterPanel = new JPanel();
            everything.setBorder( BorderFactory.createEtchedBorder() );
            panel1.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Scroll Pane 1" ) );
            panel2.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Scroll Pane 2" ) );
            everythingCenterPanel.setLayout( new BoxLayout( everythingCenterPanel, BoxLayout.Y_AXIS ) );
            panel1.add( scrollPane1 );
            panel2.add( scrollPane2 );
            everythingCenterPanel.add( panel1 );
            everythingCenterPanel.add( modeOptions );
            everythingCenterPanel.add( panel2 );
            everything.add( everythingCenterPanel );
            add( everything );
        public static void main ( String[] args )
            new Example().setVisible( true );
    }Try changing between Mode 1 and Mode 2 (via the Mode menu) to see how the text areas resize as the object between them grows and shrinks. This behavior is correct.
    What is incorrect is what happens when the user enters a large amount of text into one of the text boxes (6 or 7 lines of text should be enough to create the problem) and switches between modes.
    I've tried using the getSize and setSize methods of various components at various points in the program but none seem to work effectively. The closest thing I've been able to do is to keep the JTextAreas, the JScrollPanes, and the JPanels holding them to remain the same sizes, but the text still pushes the panel between the JTextAreas down (and possibly out of) the window, leaving a blank area between the edge of the JPanel containing the JScrollPane and the JPanel in the center.
    The JPanels containing the JScrollPanes must be able to resize correctly as the user resizes the window, so a constant size would not work in this situation.
    Any help is greatly appreciated.

    What is incorrect is what happens when the user enters a large amount of text into one of the text boxes I don't notice anything happening when I add text to the text area. The scrollbars appear as is expected. The only difference for me when I switch between mode 1 and 2 is that the center panel changes in size slightly. This is because the panel is using a FlowLayout which by default has a 5 pixel vertical gap between each component. This is easily fixed by using:
    JPanel temp = new JPanel( new FlowLayout(FlowLayout.CENTER, 5, 0) );I know you tested using JDK1.5 since I had to make the following change in order to get the example to work:
    getContentPane().add( everything );
    So maybe this is a version problem since I don't notice anything out of the ordinary other than what I already mentioned.

  • JSplitPane problem with JTextArea

    The following piece of code has the problem in it. When you resize the splitpane you won't be able to decrease the size because of the setLineWrap(true).
    I am also wondering why the button in the bottom moves (and how do I stop it from moving) when the splitpane is made bigger.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    public class HMI extends JFrame {
         private JPanel map;
         private LeftMenu leftMenu;
         private JSplitPane split;
         public HMI(String title) {
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                   SwingUtilities.updateComponentTreeUI(this);
              catch (Exception ex) {System.out.println("Look and feel does not exist");}
              map = new JPanel();
              leftMenu = new LeftMenu();
              split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftMenu,map);
              setLayout(new BorderLayout());
              add(split, BorderLayout.CENTER);
              split.setOneTouchExpandable(true);
              split.setBorder(BorderFactory.createEmptyBorder());
              setSize(1024,768);
              setLocationRelativeTo(null);
              setVisible(true);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
    //NESTED
    public class LeftMenu extends JTabbedPane {
         TabLogg logg;
         public LeftMenu() {
              logg = new TabLogg();
              addTab("Logg",null,logg,"Visar loggar av information f�r kartan");
    //NESTED
    public class TabLogg extends JPanel {
         private JButton reset = new JButton("Clear logg");
         private TitledBorder border = BorderFactory.createTitledBorder("Logg");
         private JTextArea text = new JTextArea();
         public TabLogg() {
              setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
              text.setLineWrap(true);
              text.setEditable(false);
              reset.setAlignmentX(Component.RIGHT_ALIGNMENT);
              add(text);
              add(reset);
              text.setText("testststg sd sdgs gsdg sd gs gsdgsdg");
         public static void main (String[] arg) {
              HMI human = new HMI("V�ltnavigeringssystem Interface - Ny");
    }

    I want the button to stay alligned to the very left. Read the Swing tutorial on [How to Use Box Layout|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html] for an explanation and example of how the alignment of components works.
    Also, use the following to maximize the frame:
    //setSize(1024,768);
    setExtendedState(JFrame.MAXIMIZED_BOTH);

  • Problem with method "write" in POI Library.

    Best regards, I have the following problem: I have a application in Oracle BPM 10g, that generates a file in Excel. First it upload a template, then query the data base, and storage this data in "POI Object" of type "XSSFWorkbook"; all of the this, at memory.
    The problem is when I try to write this object  "XSSFWorkbook", in the file(generate a Physical File), the file size is about 35 MB, usgin the method wb.write(out) of the "POI Library", my server spend about 15  minutes, generating blocks.
    I' like that some help me to solve this problem, maybe making any setting in my server.
    My Servers are:
    Application Server: Oracle WebLogic 10.3.1
    and File Server: Oracle Linux. Memoy: 32GB
    I show you the code in java:
                rsQuery = generarTablas(sStoredProcedure,xmlTableroControl);
                InputStream inp = JExcel.cargarPlantillaLectura(sRutaOrigen + sNombreOrigen + ".bck");
               XSSFWorkbook  wb = new XSSFWorkbook(inp);  //DESCOMENTAR
              wb.setForceFormulaRecalculation(true);
                int vnHoja = 0;
                String vsTabla = "";
                while(rsQuery.next()){
                    vnHoja  = rsQuery.getInt(1);
                    vsTabla = rsQuery.getString(2);
                    outResultado = new BufferedWriter (new FileWriter("/tmp/"+String.valueOf(nOrden)+vsTabla+".txt"));
                    outResultado.write("vsTabla: "+vsTabla+" Hoja : "+String.valueOf(vnHoja)+  "\n"+String.valueOf(Util.getTodayTime()));
                    outResultado.close();
                  nOrden ++;
                    this.rsConsulta = consultar(vsTabla);
                  if(_getRowCount(this.rsConsulta)>0)
                        generarHoja(wb, 6, vnHoja);
                        this.rsConsulta = null;//agregado 12/06/2013
                 File tempFileXLS = File.createTempFile(sNombreDestino + this.sFechaFin + "_", ".xlsx");
                ruta = sRutaDestino + tempFileXLS.getName();
                OutputStream out = new FileOutputStream(ruta);
                inp.close();
                wb.write(out);//---------------------> PROBLEM

    Best regards, I have the following problem: I have a application in Oracle BPM 10g, that generates a file in Excel. First it upload a template, then query the data base, and storage this data in "POI Object" of type "XSSFWorkbook"; all of the this, at memory.
    The problem is when I try to write this object  "XSSFWorkbook", in the file(generate a Physical File), the file size is about 35 MB, usgin the method wb.write(out) of the "POI Library", my server spend about 15  minutes, generating blocks.
    I' like that some help me to solve this problem, maybe making any setting in my server.
    My Servers are:
    Application Server: Oracle WebLogic 10.3.1
    and File Server: Oracle Linux. Memoy: 32GB
    I show you the code in java:
                rsQuery = generarTablas(sStoredProcedure,xmlTableroControl);
                InputStream inp = JExcel.cargarPlantillaLectura(sRutaOrigen + sNombreOrigen + ".bck");
               XSSFWorkbook  wb = new XSSFWorkbook(inp);  //DESCOMENTAR
              wb.setForceFormulaRecalculation(true);
                int vnHoja = 0;
                String vsTabla = "";
                while(rsQuery.next()){
                    vnHoja  = rsQuery.getInt(1);
                    vsTabla = rsQuery.getString(2);
                    outResultado = new BufferedWriter (new FileWriter("/tmp/"+String.valueOf(nOrden)+vsTabla+".txt"));
                    outResultado.write("vsTabla: "+vsTabla+" Hoja : "+String.valueOf(vnHoja)+  "\n"+String.valueOf(Util.getTodayTime()));
                    outResultado.close();
                  nOrden ++;
                    this.rsConsulta = consultar(vsTabla);
                  if(_getRowCount(this.rsConsulta)>0)
                        generarHoja(wb, 6, vnHoja);
                        this.rsConsulta = null;//agregado 12/06/2013
                 File tempFileXLS = File.createTempFile(sNombreDestino + this.sFechaFin + "_", ".xlsx");
                ruta = sRutaDestino + tempFileXLS.getName();
                OutputStream out = new FileOutputStream(ruta);
                inp.close();
                wb.write(out);//---------------------> PROBLEM

  • Problems with RS232 write/read.

    I have a serial device, device responds to ASCII messages:
    Reguest string:
    !1100/
    Responce from device:
    !1100/#xx$xxxx/
    x - ASCII characters.
    I need to communicate with devise using RS232. Device has RS485 port (2-wire). RS232/RS485 converter data direction is controled by RTS line.
    In my program I do something like this( single read for now): configure serial port, delay, asserted RTS line, transfer string, delay, unasserted RTS, read string, close port. I use VISA serial. Now I receive garbage. Where the problem might be ?

    I tried other RS485 coverter ( with auto direction). My program works fine:
    Request to device:
    !1100/
    Responce from device:
    #00$xxxx/
    Also using port monitor program I monitored data flow between original software (it comes with device) and device.
    Reguest string:
    !1100/
    Responce from device:
    !1100/#xx$xxxx/
    x - ASCII characters.
    So first is request echo and then responce from device.
    Manipulating RTS line I only managed to receive request echo, but no responce.
    Please see attached VIs: GIA10N - with no RTS control, and GIA10N_RTS - with RTS control ( I receive only request echo with it).
    I am sure that my RS232/RS485 converter works standart way, because using serial comms software ( "Advanced serial port monitor") whitch dont know anything about my device I receive responce when I enable "RS485 interface mode". Then I get this:
    Reguest string:
    !1100/
    Responce from device:
    !1100/#xx$xxxx/
    x - ASCII characters.
    Attachments:
    GIA10N.vi ‏61 KB

  • Problem with Log Writer

    Hi,
    I got the alert from OEM that 1 session is blocking another 3 sessions. When i came to know what is that session, i found that the blocking session is caused by LGWR, it is blocking other 3 sessions.
    How can i avoid the session which is caused by LGWR, to avoid the blocking of other sessions.
    Thanks,
    Mahi

    I have never heard of log wirter locking user sessions, I suggest you use the following SQL next time you see this problem to identify lokers and lock waiters:
    set feedback off
    set echo off
    set pause off
    set linesize 110
    column osuser format a15
    column username format a15
    column SCHEMANAME format a15
    column COMMAND format a25
    select 'lock waiter: ',s.sid,p.spid os_pid,s.PROCESS,s.status, s.osuser,s.username,
    s.SCHEMANAME,s.COMMAND,
    s.MACHINE,s.MODULE,s.SERIAL#, s.LOCKWAIT,s.action, s.type
    from v$session s, v$process p
    WHERE s.paddr = p.addr
    and s.lockwait is not null
    order by 4;
    select 'locker: ',s.sid,p.spid os_pid,s.PROCESS,s.status, s.osuser,s.username,
    s.SCHEMANAME,s.COMMAND,
    s.MACHINE,s.MODULE,s.SERIAL#, s.LOCKWAIT,s.action, s.type
    from v$session s, v$process p
    WHERE s.paddr = p.addr
    and s.sid in
    (select SESSION_ID from DBA_LOCKS
    where BLOCKING_OTHERS <> 'Not Blocking')
    order by 4;
    spool off
    Bobby A.
    Edited by: babak akbari on May 8, 2009 2:06 PM

  • Having problems with pdf writer,

    When I print to pdf, the program doesn't work.
    Have tried to update XI standard.
    Get a report:
    Cant read settings file for Adobe pdf in:
    C:\ProgramData\Adobe\Adobe PDF\Settings\Standard.joboptions

    Hi Jan,
    I would recommend you to refer this thread Link : Adobe PDF Settings file read error in :C:\ProgramData\Adobe\Adobe PDF\Settings\Standard.joboptions and try the solution provided on this thread. Please let me know if you face any problem.
    Regards,
    Rahul

  • Problems with SocketChannel.write(ByteBuffer buff).

    I am using the following version of JDK on Red Hat Linux
    java version "1.4.2_01"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
    Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
    I am using SocketChannel's write method mentioned above to write data to the SocketChannel. When data is being written on the SocketChannel via this write method and the underlying socket is closed by the receiving endpoint, I expect this method to throw an exception. This method does not throw any exception and returns me 0 as the value of number of bytes written out.
    The way my code is written out, it ends up going in an infinite loop. Now, I can very well fix my code to not run in an infinite loop, but is anybody else seeing this? Is this a valid behavior? Am I doing something wrong?
    Following is the code snippet that writes data to the SocketChannel. Note that writeBuffer is an instance of ByteBuffer and sc is an instance of SocketChannel. Both these variables are member variables in my class:
    public void write(byte[] buff, int offset, int length)
        throws IOException
        int toBeWritten = 0;
        while (length > 0)
            int writeOffset = offset;
            toBeWritten = writeBuffer.remaining();
            if (toBeWritten >= length)
                // All the bytes that are scheduled to be written will be
                // written.
                toBeWritten = length;
                length = 0;
            else
                // Only some of the bytes that are scheduled to be written will
                // be written.
                length -= toBeWritten;
                offset += toBeWritten;
            writeBuffer.put(buff, writeOffset, toBeWritten);
            // toBeWritten is the number of bytes that need to be written out.
            while (writeBuffer.position() != 0)
                // position = toBeWritten.
                writeBuffer.flip();
                // position = 0, limit = toBeWritten.
                int wrote = sc.write(writeBuffer);
                // position = wrote, limit = toBeWritten.
                // Compact the write buffer. It is very much possible that all
                // the bytes have not yet been written out.
                writeBuffer.compact();
                // The data that was written out, is now removed from the write
                // buffer. position = toBeWritten - wrote, limit = capacit
    }Thanks in advance!!

    When ByteBuffer.write(...) return 0, it means this
    socket is closed gracefully by another peer. the
    socket is need to re-connect again.Oh.. I forgot to mention, I am using non blocking SocketChannel. As per the Java docs for write(ByteBuffer src) method in WritableByteChannel:
    "Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer."
    So, I cannot assume that if the write method returns 0, the socket is closed by another peer.

Maybe you are looking for

  • How can I display an analog input to PXI-5105 out on LabVIEW?

    Hi ALL, I am very very new to LabVIEW and I just started to fiddle around with it. I am running LabVIEW 2010 SP1 version on Windows 7 OS. I also have NI PXIe-1073 chassis with PXIe-6361 and PXI-5105 modules and the chassis is connected to my PC via P

  • Adobe PSE 11 won't install: error 1321

    I bought adobe PSE 11, when installing, error 1321: "Installer has unsufficient privelages to modify c:\windows\installer"   appears.    I have tried running as admin, but nothing .  What do I do? 

  • Rasterize PDF graphics

    I've built a presentation where almost every slide has one or more PDF graphics (actually Illustrator files). They load okay on the mac (slight lag when displaying the slides with lots of them), but I'm getting horrible lag on the iPhone version. I s

  • Will Keynote '09 version 5.1.1 run on 10.7 Lion?

    Will Keynote '09 version 5.1.1 run on 10.7 Lion? iMac 7.1 Intel core2 duo 2.8 GHz Bus speed 800MHz

  • Change time machine back up settings

    I'm sorry, there's probably a million questions for this but I can't find the right one. My hard drive is about 330 gigs and time machine has stuffed it to the brim. Considering the fact that my mbp doesn't have that much space on it, I don't see why