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 & HelpSyntax Questions › Text Area in 2nd window
Page Index Toggle Pages: 1
Text Area in 2nd window (Read 768 times)
Text Area in 2nd window
May 22nd, 2009, 6:48am
 
Hi all,

I'm sure this is a simple Java question, but it's eluding me so I thought I'd post here:

I'm trying to add a Text Area to a 2nd "console" window for a current Processing app. I have it working fine when it's added to the main display window (simple example below):

Code:

// add text area to display window

Panel inputPanel;
TextArea textarea;

void setup(){
 size(320, 110);
 background(50);

 inputPanel = new Panel();  
 inputPanel.setLayout(new BorderLayout());
 add(inputPanel);
 inputPanel.setBounds(5, 5, 310, 100); // left x, top y, width, height
 
 textarea = new TextArea("");  
 // A border layout lays out a container, arranging and resizing its components to fit in five regions:
 // Each region is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER.
 inputPanel.add(textarea, BorderLayout.CENTER);
 setLayout(new BorderLayout());
}

void draw() {
}


But I can't get it to work in the 2nd window. See below:
Code:

// attempting to draw text area in 2nd window

UIWindow uiWindow;
PFont font; // must load a font for TextButton class

void setup() {
 uiWindow = new UIWindow(320, 110, 15,"Console"); // width, height, framerate, font name, window name
 background(0);
 size(320, 240);
 frameRate(60); // framerate for main window
}

void draw() { // add stuff here to draw to main window
 background(0);
}


public class UIWindow extends PApplet { // class for 2nd window
 Frame frame;
 int width;
 int height;
 int fps;
 String windowName;
 
 Panel inputPanel;
 TextArea textarea;  

 UIWindow (int w, int h, int framerate, String name) {
   width = w;
   height = h;
   fps = framerate;
   windowName = name;
   frame = new Frame();
   frame.setBounds(0, 0, width, height);
   frame.setLocation(0, 0);
   frame.setResizable(false); // set to true to change window size
   frame.add(this);
   this.init();
   frame.show();
 }

 void setup() {
   size(width, height, P2D);
   frameRate(fps); // framerate for 2nd window
   frame.setTitle(windowName);
   //noLoop();
   
   inputPanel = new Panel();  
   inputPanel.setLayout(new BorderLayout());
   add(inputPanel);
   inputPanel.setBounds(5, 5, 310, 100); // left x, top y, width, height
   
   textarea = new TextArea("");  
   // A border layout lays out a container, arranging and resizing its components to fit in five regions:
   // Each region is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER.
   inputPanel.add(textarea, BorderLayout.CENTER);
   setLayout(new BorderLayout());    
 }

 void draw() { // add stuff here to draw to 2nd window
   // draw stuff in console window
 }
}


Can anyone help. I'm not interested in using the controlP5 library for this - would rather figure this out. Thanks for the help!

best,
Zachary
Re: Text Area in 2nd window
Reply #1 - May 22nd, 2009, 8:33am
 
I'm a bit confused on what trouble you're having.

When I copy your code into a sketch, I get two windows; an empty one (sketch), and another with a text area.
Re: Text Area in 2nd window
Reply #2 - May 22nd, 2009, 5:22pm
 
Hi NoahBuddy,

Compare the first code snippet with the second and you'll see what I'm talking about. You can't type into the second text area, or at least I can't. Can you?

best,
Zachary
Re: Text Area in 2nd window
Reply #3 - May 22nd, 2009, 9:47pm
 
I tried this on two machines now:

The first, XP, Intel: worked.

Second, Win2K, AMD (64 bit, running at 32 bit, not sure if that makes the difference).

When I added this to the setup() of UIwindow, it worked:
Code:
void setup() {
 ...
 frame.pack();
}


I usually use a null layout, but noticed pack() inserted by Netbeans when I have other types. It tells the frame to set the components to their preferred size/position/etc.
Re: Text Area in 2nd window
Reply #4 - May 22nd, 2009, 10:15pm
 
frame.pack(), that's it! Thanks for the help.

best,
Zachary
Page Index Toggle Pages: 1