Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How to call the Loop in Jtextfield

Right now you are directing your boxes to System.out. So you need to direct them to your text component.

Also, you can't use JTextField for this because it is not multiline. Instead, you should use something like a JTextArea inside a JScrollPane.

resultTF = new JTextArea();
Font f = resultTF.getFont();
resultTF.setFont(new Font(Font.MONOSPACED,
f.getStyle(), f.getSize()));

add(new JScrollPane(resultTF));


for(int i = 0; i < height; i++) {
    for(int j = 0; j < width; j++) {

If you don't want a scroll pane, you could also, for example, create the text area with specific rows and columns (new JTextArea(5, 5)), use a StringBuilder to create your box and use setText instead of append.

As a side note, you should be creating your GUI on the Swing event thread. In other words, your main should be wrapped in a call to invokeLater:

public static void main(String[] args)
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            Box p = new Box();

See also:

Categories : Java

Related to : How to call the Loop in Jtextfield
Outputting the value from a JTextField using .getText()
You should place String playerName = jTextFieldPlayerName.getText(); inside actionPerformed method as you are printing global playerName but it's never been initialized thats why it prints null. You can do something like below. public void actionPerformed(ActionEvent evt) { Object src = evt.getSource(); String playerName = jTextFieldPlayerName.getText(); if (src == startText1Contin

Categories : Java
taking text from a JTextField and placing it into a JTextArea
As Andrew Thompson already indicated, make sure your code at least compiles and has a main method. The TextEditor class you provided is missing the loadMenuBar & loadToolBar methods, the actionPerformed & loadCalculator methods are sort of merged together, and a main method is missing in both classes. Please formulate your question as best as you can to get good answers. I think the reaso

Categories : Java
Recently Add
Concurrent collection to 50/50 read/write
How to get unique members of object class (groupofUniqueNames) from an ldap server using java
Custom error reporting: how to log down function arguments (and possibly locals) in an exception handler?
Websphere MQ message redelivery
How to use BigDecimal to achieve following code instead of using double or float?
What exactly do the service() method of this HttpServlet?
Why does the Java API use int instead of short or byte?
Hibernate. One to one mapping without cross references
How to pass array to a java method
BooleanFieldEditor doesn't load value from PreferenceStore
NoClassDefFoundError when I call the class through commnad line
Shopizer Search
Java - Bank System + Transaction Function
Hadoop security using Apache DS / Apache Directory Studio
Multiple property-placeholder with overlapping locations does not work?
could not remove/add jpanel in jframe
Java garbage collection verbose not working
If child class has a variable with same name as private variable in parent what will be used?
Jackson parse json with a one-to-many relationship in a single step
Excel opens wrong view after generating in Apache POI
On Switch How to use logic operator on case JAVA
Java: What is the absolut first second in Calendar?
Waiting One Second for a button click, if button not clicked call function
Fastest way to extract part of a large JSON File
copy directory operation using linux command in java
Figuring out how to Format Printing
Why does @FunctionalInterface have a RUNTIME retention?
Collision detection Libgdx rectangles
Cannot find symbol in method changeRecL but declared in main method
Receiving " Connection reset" when connecting from dotnet client to a java server
© Copyright 2017 Publishing Limited. All rights reserved.