Solved

Java - Why doesn't this JFrame work

Posted on 2016-11-19
3
41 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
network + 7 80
split53 challenge 7 78
Java asynchronous logging 4 50
Apps blocked by Java 9 63
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

910 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

23 Experts available now in Live!

Get 1:1 Help Now