How To Change Location Of JTextArea At Runtime

Feb 11, 2014

I am using Swing, I have a JPanel and in it there is a JTextArea and a JButton. I want the JTextArea to move when the button is clicked on. I'm Not really sure how to do the action listener for the button. at the moment the JTextArea only moves once when the button is clicked on, but i want it to move every time the button is clicked on.

This is what i have so far:

moveButton = new JButton("MOVE");
moveButton.setName("move");
moveButton.setBounds(20, 140, 70, 40);
text = new JTextArea("hello");
text.setEditable(false);
text.setBounds(x, 50, 40, 20);
panel.add(moveButton);
panel.add(text);

In the actionPerformed method this is what it does:

text.setBounds(x + 50, 50, 40, 20);
panel.add(text);
text.setVisible(true);

View Replies


ADVERTISEMENT

Change Font / Orientation For JTextArea Print

Jul 5, 2014

I wish to print the content of a JTextArea. I know I can do this with textarea.print(). However, I wish to print in a different font, font size and orientation from that of the JTextArea itself. I have been able to change the orientation by setting print attributes

PrintRequestAttributeSet printAttributes =
new javax.print.attribute.HashPrintRequestAttributeSet ();
printAttributes.add(javax.print.attribute.standard .OrientationRequested.LANDSCAPE);

And then using the textarea.print() method that allows me to set attributes. However, I haven't found any way to set the font and font size.

View Replies View Related

Can't Change GridWorld Grid During Runtime

Jun 5, 2014

I have a question about updating a grid during runtime in GridWorld. I'm making a game called Flood-It (basically, you click on squares to change their color and attempt to get all of the squares the same color in the grid) and I'm having trouble with changing the grid size. I made my own world class, called CellWorld.

import info.gridworld.actor.*;
import java.util.ArrayList;
import info.gridworld.grid.Location;
import java.awt.Color;
import javax.swing.JOptionPane;

[code]...

Now, let me narrow down the issue. It is in the runner class:

world.setGrid(new BoundedGrid<Actor>(world.getLength(),world.getWidth()));

Whenever a user wants to change the grid size after playing the game, this is supposed to set the grid to the new updated size, but it never changes in the actual game, i.e. the user just won a 2x2 game, attempts to change the size to 10x10, but the grid stays 2x2. By debug testing, I can say for certain that everything else works, such as the maxStepCalc and loading the grid. The only issue is the new grid not showing up.

View Replies View Related

Swing/AWT/SWT :: Change Location Of Component Using Grid Bag Layout

Jun 13, 2014

How to change the location of a grid bag positioned component after it's already been added to the layout earlier?

Example is if I want component 1 to change from row 1 to row 2.

View Replies View Related

Servlets :: HTML Not Printing If Change Location Of Println Statement?

Mar 2, 2015

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;

[Code] ....

When I run the above code , the html is not printed ?

View Replies View Related

How To Get JTextArea To Display Over The Top

Sep 21, 2014

So I have been working on this code for a bit now... basically just supposed to be a display for a calculator, next week in my class we are learning about how to make it do stuff. so it's supposed to just look right for now. Should look something like this actually

My first question is this, how can I get the JTextArea to display over the top like the example?

My second question is I just started getting an error that compiled before, and I haven't changed anything about this line. Here is everything.

import java.awt.*;
import java.awt.font.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class CalcDisplay extends JFrame{
String[] buttonText = {

[Code]...

the output looked something like this though note this is an old screengrab from while I was working on it. I have since gotten it to color correctly and I have a jtextarea below the numbers. though I need to get it to implement above the numbers and can't figure out how to do so the other example is what it should look like, disregard the color choice.The error I was getting appeared on line 36

Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method setLayout(LayoutManager) in the type Container is not applicable for the arguments (GridLayout) The constructor GridLayout(int, int, int, int) is undefined

at CalcDisplay.addComponentsToPane(CalcDisplay.java:36)
at CalcDisplay.main(CalcDisplay.java:82)

This code has worked through the whole project and I haven't changed a thing.

View Replies View Related

JScrollPane / JTextArea Does Not Appear

May 29, 2014

I have a JFrame that houses a JScrollPane that houses a JTextArea (I set the console to output to the JTextArea). For some reason, when the frame appears, text is being printed like usual, but the scroll pane isn't rendered unless I hover over it or click on it. Also when I resize the frame, nothing appears unless I hover over it or click on it.

Code:

package voxel;
import java.awt.Dimension;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.logging.Logger;

[Code] ....

I've tried repainting the frame when everything is added to the frame and packed, but it doesn't change anything. I tried searching for other people who had the same problem, but most of them were relating to setting the layout to null (which I don't do) and using JPanels.

View Replies View Related

How To Refresh JTextArea

Apr 21, 2014

I created this JTextArea with some text in it. And it also has few variables.

Sth like that:

Java Code:

protected JTextArea textLog;
textLog = new JTextArea();
textLog.append("test: "+variable); mh_sh_highlight_all('java');

And now while I use button that changes variable value, in textLog variable still shows old value.

Tried to use remove(textLog); textLog.validate(); etc(remove, validate, revalidate, add, repaint), because it works fine with JButtons, but still, in textLog variable gives me old value.

like "you should use somethingvalidate(); while clickin button and it will works", not some shit for 3032 lines with 99% of code that I don't need to do what I want.

View Replies View Related

Know If Text Fits JTextArea

Jun 17, 2014

I have a JTextArea that the user car resize. Now, I want to check if the JTextArea is displaying all the text in order to change the border color. The JTextArea line wrap is set to true. how to do this?

View Replies View Related

JTextArea Changing Txt File

Apr 24, 2014

Every time I load a txt file into a JTextArea it prints the results to the JFrame incorrectly I notice its mainly the white spaces this is happening to. I have tried a few ways to remedy this problem but it still keeps occurring? I've tried append() read() also setText() even Scanner. I have enclosed a picture of my GUI and my txt file I am using.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JTextArea;

[Code] ....

Attached image(s)

View Replies View Related

Swing/AWT/SWT :: JTable Instead Of JTextArea

May 3, 2015

i have this code when i selected a node it display the attribut and value of it in JTextArea but i want it into table :

public void valueChanged( TreeSelectionEvent event )
{
if( event.getSource() == jtree ){
{
FramePrincipale.getExplorePanelll().setText(null);
TreePath path = jtree.getSelectionPath();
String a = changeString(path);
Hashtable env1 = System.getProperties();
env1.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env1.put(Context.PROVIDER_URL, "ldap://localhost:11389/");

[code]....

View Replies View Related

Insert Smiley Images In JTextArea?

Feb 23, 2015

making an app in java.i m making app that should insert smilyes in textarea while sending a message.

View Replies View Related

Swing/AWT/SWT :: How To Implement JTextArea In Netbeans

Apr 20, 2014

I have dragged and dropped a jTextArea from netbeans palette onto my form. But when I right clicked for Event > action > actionPerformed for implementation, I realized such was not there, unlike the jTextField component. For example, I have tried this but it didn't work:

//{
Import java.swing.*;
JTextArea txa = new JTextArea();
txa.getText(jTextArea1);
txa.setText(jTextArea1);
txa.setTextWrap(true);
//}

View Replies View Related

Adding Text To JTextArea From Second Class?

Feb 4, 2015

Basically , I'm trying to make a program that makes the Finch follow the object. I have made two classes :

NewOption52 and FollowClass.

Class NewOption52 contains a method which determines the properties of the GUI. Class FollowClass contains a main method which calls GUI method from class NewOption52 and it also contains several methods which dictates the Finch's behavior alongside with appending text to JTextArea feed.

When I connect the Finch and run the program , a GUI should appear and inside JTextArea should have text which says ""Please Place An Object in front of Finch And Then Tap Finch to Activate!". It didn't happen when I run the program.

Class NewOption52 :

import edu.cmu.ri.createlab.terk.robot.finch.Finch;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.*;
public class NewOption52

[code]....

View Replies View Related

Put Answer Of JCheckBox Inside Of JTextArea

Sep 17, 2014

I would like to put the answer of JCheckBox inside of a JTextArea. How to call the answer of JCheckBox if its check the response should be Yes if its unchecked the response should be No, and the yes/no answer should be appear inside JTextArea. But my problem is inside the JTextArea the answer from a JTextField and JComboBox is also there, and they should be appear in a parallel. I attached the physical appearance of the GUI.

Attached image(s)

View Replies View Related

Swing/AWT/SWT :: JTextArea Position And Size

Nov 6, 2014

I need to make a simple applet, but I'm stuck with something. This is how my applet should look:

And this is how that part looks in my applet:

What I've done until now is create one JPanel which includes two other JPanels.. The first one contains only the JTextArea you can see, and the other one includes the other elements.

I just need to make the JTextArea taller, like in the example, so everything comes into place...

View Replies View Related

Capturing Output Into GUI JTextArea Program

May 28, 2014

So I'm pretty much done with this project except I am unable to get the println statements of "Produced" & "Consumed" to display in my JTextArea on my GUI. I am completely lost as to exactly why the program just continues to create new windows repeatedly crashing. I will include the code to the 3 classes I'm working with - I'm capturing with the fac.println("") on both consumer and producer and have a method in the Factory class that tells it to print in JTTextArea

import java.util.Date;
public class Producer implements Runnable
{
private Buffer<Date> buffer;
private Factory fac = new Factory();
public Producer(Buffer<Date> buffer)

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Using SetBounds Or SetLocation On JTextArea Not Working

Oct 31, 2014

I am adding a JTextArea to my JPanel with this code:

commentTextArea.setLineWrap(true);
commentTextArea.setWrapStyleWord(true);
commentTextArea.setVisible(true);
this.add(commentTextArea);
commentTextArea.setBounds(0, 0, 100, 100);
//commentTextArea.setLocation(0, 0);

Whenever I use setLocation(0,0), the JTextArea never moves. It is always in the top middle of the screen, not at (0,0). The same goes for setBounds(0,0,100,100) BUT the height and width are set this way, just not the location. Why is this?

Full Code

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JMenuBar;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Display Console Result In JTextarea

Mar 29, 2014

I have a problem with my code,in fact I can't output the stream from console to my jTextarea,this is my code:

public class AudioFrame extends javax.swing.JFrame {
static double[] audioFile;
static String audioToDecode;
static String audioKey;
static String outputName;
static String outAudio;
static String name;
static int command;
static String textToEncode;

[Code]...

View Replies View Related

Printing Specific Lines From Textfile Into JTextArea

Jan 19, 2015

I am having trouble with reading specific lines from a text file in to a JTextArea. I want it to read only the first line of my text file and print it out in my JTextArea, however nothing is printing out.

BufferedReader a = null;
try {
a = new BufferedReader (new FileReader ("D:/FinalProjectFile.txt"));
a.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

[Code] ....

View Replies View Related

GUI JTextArea - Converting Integer To String Array

Sep 28, 2014

Run the code along with the attached csv file. The GUI contains a short explanation of what I am looking for. I have tried converting the integer array to a string array but the output is not the same as the command line. I receive errors when I compile.

View Replies View Related

Specifying File Location?

Mar 10, 2014

How to specify the file location. One way would be

PrintWriter outputFile=new PrintWriter("A:PriceList.txt");

My problem occurs when I try to specify a file location as show below

//Open an output file that appends data and does not delete it
FileWriter append_data=new FileWriter("C:hello.txt",true);
//Make a file that cvan print data into it
PrintWriter outputfile=new PrintWriter(append_data);

Apparently, I believe this is not the right way to set my own path for the file... How can I specify my file path.

One more question would be that suppose I want to specify the file location on Desktop. What the format for that?

View Replies View Related

Getting RunTime Exception ClassCastException

Feb 28, 2014

i am getting runtime Exception Saying classCastException .here is my code where i am getting classcastException.

public class ModifyDetailsServlet extends HttpServlet {
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

[code]....

View Replies View Related

Swing/AWT/SWT :: Save Text From JTextArea - String Formatting

Dec 30, 2014

I am currently working on a project that can save text from a JTextArea and also open that same saved text. The problem I am having is that when I open the saved text file it is no longer formatted.

How the file looks before saving/closing:

public class HelloWorld{
System.out.println("Hello World!");
}

How the file looks after being saved/closed then opened:

public class HelloWorld{ System.out.println("Hello World!");}

When I save the file I'm actually saving the entire thing to a single string. When I do this the String eliminates all tabbed spacing and pushes all characters to one single line.

The only ideas I had for fixing this were to either somehow use Format in the String class or record every time user tabs and add to the String.

View Replies View Related

Swing/AWT/SWT :: Give JTextArea Focus - Using It On A Panel And With JToolBar

Apr 21, 2014

I have a program with a main panel JPanel that implements KeyListener. I added a JTextArea to which I added as the KeyListener: this, meaning the main panel. I made the JTextArea fill the entire main panel because I want to catch a key press anywhere in the main panel.I catch the key presses and the program does what I want it to.

I added a JToolBar to the program; it is working just fine.Now that I have two components on the main panel - toolbar and panel with textarea -, the textarea must have the focus before it will send the KeyEvent and call keyPressed(). I don't want to expect the user to click on the main window to get the program to start or after each time they use the toolbar.

I have tried calling both requestFocus() and requestFocusInWindow() on the textarea; neither call worked. I put the toolbar at PAGE_END instead of PAGE_START; this worked to allow the program to start but I don't want to have the toolbar at the bottom and once I clicked on a toolbar button, the textarea lost the focus.

I need to be able to give the textarea the focus when the program starts and after the user uses a toolbar button. (I suspect that if I solve the problem when the program starts, I can use the same method after handling a button press.)

View Replies View Related

Swing/AWT/SWT :: Rows In JTextArea - Entering More Lines Than Limit

Jan 9, 2014

Here's a snippet of code from a program I'm making:

private void init() {
...
testInfo = new JTextArea("Progress log:
");
testInfo.setEditable(false);
testInfo.setLineWrap(true);
testInfo.setPreferredSize(new Dimension(testInfo.getPreferredSize().width, 200));
scrollPane = new JScrollPane(testInfo);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
...
add(scrollPane);
}

The problem is, the JTextArea that's created has a "limited" number of rows - it seems you can still enter more lines than the "limit", but they don't show. I thought it was a problem with the JScrollPane but I'm not so sure...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved