Solved

Java - Why doesn't this JFrame work

Posted on 2016-11-19
3
72 Views
Last Modified: 2016-11-20
Hi
I'm trying to do a Jframe that is yellow, and has a text area inside it to display results of  my program's calculations.

The JFrame seems to only consist of the JTextArea, even though the size and positioning are clearly within the frame.

What is going wrong below? Thanks

import java.awt.Color;
import java.awt.*;

import javax.swing.*;


public class FFframe extends JFrame{

	JTextArea ta;
	
	public FFframe() {
		
		this.setSize(900, 900);
		this.setLocation(0, 0);
		this.setBackground(Color.YELLOW);
		
		ta = new JTextArea();
		ta.setLocation(500, 500);
		ta.setSize(200, 200);
		ta.setBackground(Color.WHITE);
		ta.setText("ldksjvhlskjdvhlkasjdhvlkjshzvkljshljkvh");
		add(ta);
		
		this.setVisible(true);
		
		
		
	}
	
	
	public static void main(String[] args) {
		
		new FFframe();
	}

}

Open in new window

0
Comment
Question by:beavoid
  • 2
3 Comments
 
LVL 16

Assisted Solution

by:krakatoa
krakatoa earned 500 total points
ID: 41894482
Use a LayoutManager and add the TextArea to it.
0
 
LVL 16

Accepted Solution

by:
krakatoa earned 500 total points
ID: 41894488
import java.awt.Color;
import java.awt.*;

import javax.swing.*;

 

public class FFframe extends JFrame{

	JTextArea ta;
	
	public FFframe() {
		
		this.setSize(900, 900);
		this.setLocation(0, 0);
		this.setLayout(new BorderLayout());
		this.getContentPane().setBackground(java.awt.Color.YELLOW);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		ta = new JTextArea();
		ta.setLocation(500, 500);
		ta.setSize(200, 200);
		ta.setBackground(Color.WHITE);
		ta.setText("ldksjvhlskjdvhlkasjdhvlkjshzvkljshljkvh");
		this.add(ta,BorderLayout.WEST);
		
		this.setVisible(true);
		
		
		
	}
	
	
	public static void main(String[] args) {
		
		new FFframe();
	}

}

Open in new window

0
 

Author Closing Comment

by:beavoid
ID: 41895282
Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows 10 IE Certificate Issue 10 51
arguments to jar 5 35
Error in @AspectJ Based AOP with Spring 2 18
maven module vs maven project 3 48
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question