Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java - Why doesn't this JFrame work

Posted on 2016-11-19
3
Medium Priority
?
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Assisted Solution

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

Accepted Solution

by:
krakatoa earned 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

604 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