Solved

Java - Why doesn't this JFrame work

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

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 455
Bot application - advice 3 80
Setup GlassFish 4 55
How to find out if all executorservice threads have finished 2 12
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

739 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