I have class which extends JTextArea which I want to attach to JFrame.

here is constructor for for JTextArea

public MoveSelectedFiles()
	{
		area = new JTextArea(10, 40);
		setVisible(true);
	}

and here is JTextArea is added to JFrame

MovedSelectedFiles movedTextArea = new MoveSelectedFiles();
		JPanel panelTextArea = new JPanel();
		panelTextArea.add(movedTextArea);
		frame.add(panelTextArea, BorderLayout.EAST);

The JFrame is build of other 3 components where other 2 are showing OK.
Any suggestions/solutions?

Recommended Answers

All 8 Replies

You create a JTextArea but you don't add it to anything.
As a result it's never displayed.
Setting visible to true isn't going to do it, you need to add the actual JTextArea component to a container (like a JPanel).

You create a JTextArea but you don't add it to anything.
As a result it's never displayed.
Setting visible to true isn't going to do it, you need to add the actual JTextArea component to a container (like a JPanel).

don't I do that whit

MovedSelectedFiles movedTextArea = new MoveSelectedFiles();
		JPanel panelTextArea = new JPanel();
		panelTextArea.add(movedTextArea);
		frame.add(panelTextArea, BorderLayout.EAST);

I thought that is corect approche....

but your movedTextArea isn't a JTextArea according to the rest of the code you posted...
It has a JTextArea as a datafield, but that's it.

now you complitely lost me. First you say I need to attach JTextArea to JPanel for example, but when I point to peace of code you say movedTextArea is not JTextArea
so let do it again if we can

public class MoveSelectedFiles extends JTextArea
{
	private JTextArea area;
	
	public MoveSelectedFiles()
	{		
		area = new JTextArea(10, 40);
	}
...
}

this is part of the code where I declare MovedSelectedFiles and provide constructor(some parts I exclude it)

...
MoveSelectedFiles movedTextArea;
MyComponent()
	{
		frame.add(component1, BorderLayout.WEST);
		frame.add(component2, BorderLayout.CENTER);

                // add TextArea to frame
		movedTextArea = new MoveSelectedFiles();
		JPanel panelTextArea = new JPanel();
		panelTextArea.add(movedTextArea);
		frame.add(panelTextArea, BorderLayout.EAST);
        }

bring in MoveSelectedFiles
add two components to frame
add movedTextArea to panelTextArea ( I do understand i'm adding extended JTextArea, am I wrong?)
add panelTextArea to frame

can you please explain where I'm going wrong?

Your "MoveSelectedFiles" class doesn't work.
You apparently think the contained JTextArea should show up but it never will.

Just add a regular JTextArea instead, and see what happens.

what do I have to do in order to get "MoveSelectedFiles" working?

I know it sounds dump but at uni we only extend it dialog boxes, never put together frame of different components declared in seperated class files

That all depends on what you want that thing to do...
If it's just a textarea scrap it completely ;)

If it's a JPanel with some components, build it just like you would a complete dialog box, and add it to your window.
It would derive from JPanel though, not JTextArea.
If you want a JTextArea with some specific handling, just override some of its methods in it, don't wrap one in it.

OK, I got it now, will deal with it as soon I get some break from university

thank you for advice, will pm you with result

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.