We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › JTextArea edit text in processing
Page Index Toggle Pages: 1
JTextArea edit text in processing (Read 1468 times)
JTextArea edit text in processing
Mar 8th, 2010, 1:01pm
 
Hello,

I found this code
Code:

import javax.swing.*;
import java.awt.*;

int gX,gY;
ta_scroll gui;

class ta_scroll{
   private JFrame f; //Main frame
   private JTextArea ta; // Text area
   private JScrollPane sbrText; // Scroll pane for text area
   private JButton btnQuit; // Quit Program
   
   
   public ta_scroll(){ //Constructor
       // Create Frame
       f = new JFrame("Swing Demo");
               f.setBounds(gX+50, gY+120, 200, 20);  //set the f frame position according to main frame
               f.removeNotify();f.setUndecorated(true);
       
       // Create Scrolling Text Area in Swing
       ta = new JTextArea("text ici", 5, 20); // définie la taille de la zone de texte
ta.setLineWrap(true);
sbrText = new JScrollPane(ta);
sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);        
   }

   public void launchFrame(){ // Create Layout
       // Add text areato frame
f.add(sbrText);
//Display Frame
       f.pack();
       f.setVisible(true);
   }
}


void setup(){
     size(500,500);
   }
   
void draw(){
     gX=frame.getX();gY=frame.getY();println(gX);
     if (frameCount==4){gui = new ta_scroll();gui.f.setAlwaysOnTop(true);gui.launchFrame();}
   }


This work very well but it open the text area in a new frame.
I would like to edit a text in the main frame so i tried this

Code:


import javax.swing.*;
import java.awt.*;



JScrollPane sbrText; // Scroll pane for text area
JTextArea ta = new JTextArea("text ici", 5, 20); // définie la taille de la zone de texte

void setup()
{
 size(500,500);
 ta.setLineWrap(true);
 sbrText = new JScrollPane(ta);
 sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
}

void draw()
{
   frame.add(sbrText);
   //this.add(sbrText);   //doesn't work either
   //frame.pack();     //doesn't work here (reduce frame
}


but nothing apear in the frame.
I don't know why and what i must do to use this text editor in the processing frame

thanks for help me
Re: JTextArea edit text in processing
Reply #1 - Mar 8th, 2010, 2:22pm
 
Look at PApplet for example:
Quote:
Note that you should not use AWT or Swing components inside a Processing applet. The surface is made to automatically update itself, and will cause problems with redraw of components drawn above it. If you'd like to integrate other Java components, see below.

That's probably the reason why the Swing component is opened in a new frame.
A possible alternative is to use noLoop() before spawning a Swing component.
Re: JTextArea edit text in processing
Reply #2 - Mar 8th, 2010, 3:22pm
 
You could also use one of the gui libraries written specifically for Processing like G4P by Peter Lager:

http://www.lagers.org.uk/g4p/index.html
Re: JTextArea edit text in processing
Reply #3 - Mar 8th, 2010, 11:29pm
 
Well,

the result is not very similar:
-text area doesn't wrap text when it is to long
-no scroll bar moving the text in its area
-impossible to select word or groupe to cut  or copy it
...

but  it's possible to use some java class for processing
i'm sure there is a way to use this one ...
Page Index Toggle Pages: 1