Java programming


Ad: Buy Girls Und Panzer Merch from Play Asia!

dchaosblade

- Lord of Chaos
Retired
Okay, so as many of you who participated in our last FTV League may know, I have been working on a new and improved Java Applet that will write up all the forum code for the user quickly and easily without the need of writing it themselves or trying to hunt out and change words from a pre-written template.
I already have pretty much ALL of the Applet written out and working, but I've come upon two stumbling blocks (which should have quick/easy solutions) that I wanted to request help with.

First, I am trying to find a component like JTextArea that will allow me to use commands like \n and the like (which JLabel does not allow) and will allow the user to both highlight the text (like a JTextArea) AND right-click it - which JTextArea does not allow (even if you setEditable(true)).
JTextPane and JTextEditor both do NOT allow you to access the right-click menu apparently.

My second problem:
The way my applet currently works, it displays a pretty little GUI with buttons, radio buttons, and labels, etc. After the user has finished making all the selections, I
CODE setVisible(false);
removeAll();
add(JTextArea(code));
setVisible(true);
all with requisite getContentPane's or etc as needed. My problem is that the JTextArea doesn't actually become visible...you have to click in the Applet area for it to pop into visibility (otherwise you just see a white box). I've tried removing setVisible, rearranging where they are in the code, all to no avail. I'm not sure WHY it wont become visible, but it wont.
I've also tried getFocus(), btw.


So, if anyone knows a fix to either of the above problems (an effective way to display the string or a way to make the JTextArea be visible without clicking on the applet), please enlighten me.
If you'd like to see how the Applet currently looks, refer to my post in the FTV League Discussion thread, where you can grab a copy of the JApplet - this may be particularly useful for people trying to fix the second problem to see what I'm talking about.

If you would like snippets of relevant code, feel free to ask.

And yes, I know I can make the JTextArea I currently have prettier, but I plan to replace it anyway (remember?) so I haven't bothered doing anything with it.
 
How about trying to refresh the frame by calling repaint()? This is of course for your second problem. That should display the textarea unless you did something really weird.

About your first problem (no right click menu): As far as I know you must implement the right click menu yourself however normal windows commands such as ctrl+c, ctrl+v will work automatically. That is why right clicking the text box doesn't do anything. You never made it do anything.
 
Nope, call to repaint() doesn't do it, I thought of that.
Nor do variations (such as getContentPane().repaint(); or jTextField.repaint(); etc). I'm really confused as to why it doesn't work.

CODE setVisible(false);
getContentPane().removeAll();

JTextArea field = new JTextArea(code);

/* Also tried:
JPanel text = new JPanel();
text.add(field);
getContentPane().add(text);
*/

getContentPane().add(field);
setVisible(true);

// Also tried: field.setVisible(true);

/*  Tried the following for repaint:
repaint();
getContentPane().repaint();
field.repaint();
this.repaint();
*/



EDIT: Quick update, sometimes clicking in the applet area doesn't make the text appear either ~_~ This seems to happen randomly, and reloading the page (and therefore running through the process again - a 10 second task) usually will let it appear. Once again, I have NO idea why this happens, nor why it only happens occasionally - I've tried replicating results and am usually unsuccessful...
 
Playasia - Play-Asia.com: Online Shopping for Digital Codes, Video Games, Toys, Music, Electronics & more
Back
Top