Solved

Java - Why doesn't this JFrame work

Posted on 2016-11-19
3
14 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
Comment Utility
Use a LayoutManager and add the TextArea to it.
0
 
LVL 16

Accepted Solution

by:
krakatoa earned 500 total points
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Receive file in Servlet 1 36
network + 7 73
nestparen challenge 4 55
wordlen challenge 3 46
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now