12 Replies - 504 Views - Last Post: 02 April 2013 - 01:39 PM Rate Topic: -----

#1 novakasss  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 352
  • Joined: 11-July 12

Too wide window

Posted 24 March 2013 - 11:15 PM

I have jpanel with jtextArea in it. Jpanel is added into JFrame. I added some functionality to change the size of the text. But when I change it for example from 12 to 16 my window becomes too wide. How should I avoid that?
Is This A Good Question/Topic? 0
  • +

Replies To: Too wide window

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1390
  • View blog
  • Posts: 3,075
  • Joined: 05-April 11

Re: Too wide window

Posted 24 March 2013 - 11:18 PM

By making the JPanel or JTextArea a fixed size I guess
Was This Post Helpful? 0
  • +
  • -

#3 Gungnir  Icon User is offline

  • Your Imaginary Friend

Reputation: 152
  • View blog
  • Posts: 527
  • Joined: 21-May 11

Re: Too wide window

Posted 24 March 2013 - 11:18 PM

The Jpanel becomes too wide for the JFrame, or the JFrame becomes too wide? What is 'window' referring to?
Was This Post Helpful? 0
  • +
  • -

#4 novakasss  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 352
  • Joined: 11-July 12

Re: Too wide window

Posted 24 March 2013 - 11:33 PM

View PostGungnir, on 24 March 2013 - 11:18 PM, said:

The Jpanel becomes too wide for the JFrame, or the JFrame becomes too wide? What is 'window' referring to?

Jframe.
Here is my JPanel class.
public class TextFile extends JPanel{

	private JScrollPane textField;
	private JTextArea textArea;
	private String currentFont = "Serif";
	private int currentSize = 12;
	
	public TextFile(){
		textArea = new JTextArea(58,115);
		textArea.setFont(new Font(currentFont,Font.PLAIN,currentSize));
		textField = new JScrollPane(textArea);
		add(textField);
	}
	
	public void setFontSize(int size){
		currentSize = size;
		textArea.setFont(new Font(currentFont,Font.PLAIN,currentSize));
	}
	
	public JTextArea getArea(){
		return textArea;
	}
	
	public void addText(String s){
		textArea.append(s);
		textArea.append("\n");
	}
}

textArea = new JTextArea(58,115);
This is not fixing size?
Or I need to fix size for jscrollpane?

This post has been edited by novakasss: 24 March 2013 - 11:34 PM

Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Too wide window

Posted 25 March 2013 - 03:50 AM

View Postnovakasss, on 25 March 2013 - 02:33 AM, said:

textArea = new JTextArea(58,115);
This is not fixing size?

This is specifying the number of rows and columns in the JTextArea
Sure that if you increase the font width you will need more space to display the 115 characters of a line
Was This Post Helpful? 0
  • +
  • -

#6 novakasss  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 352
  • Joined: 11-July 12

Re: Too wide window

Posted 01 April 2013 - 03:35 AM

View Postpbl, on 25 March 2013 - 03:50 AM, said:

View Postnovakasss, on 25 March 2013 - 02:33 AM, said:

textArea = new JTextArea(58,115);
This is not fixing size?

This is specifying the number of rows and columns in the JTextArea
Sure that if you increase the font width you will need more space to display the 115 characters of a line

How should I set size in pixels? not rows and columns? I tried to use setSize() and some other methods of JTextArea but it doesn't work.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Too wide window

Posted 01 April 2013 - 03:45 AM

You will have to set the preferredSize in prixel of the JPanel containing the JTextArea
Was This Post Helpful? 0
  • +
  • -

#8 novakasss  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 352
  • Joined: 11-July 12

Re: Too wide window

Posted 01 April 2013 - 04:35 AM

View Postpbl, on 01 April 2013 - 03:45 AM, said:

You will have to set the preferredSize in prixel of the JPanel containing the JTextArea

But I can't use setPrefferedSize() on JPanel. It gives me error. Or there is another way doing that?
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Too wide window

Posted 01 April 2013 - 07:04 AM

After more than 150 posts you should know that "it gives me an error" is a completly useless remark.

Post the actual error with the stack trace.
Was This Post Helpful? 0
  • +
  • -

#10 novakasss  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 352
  • Joined: 11-July 12

Re: Too wide window

Posted 01 April 2013 - 10:31 AM

View Postpbl, on 01 April 2013 - 07:04 AM, said:

After more than 150 posts you should know that "it gives me an error" is a completly useless remark.

Post the actual error with the stack trace.


The method setPrefferedSize(int,int) is undefined for the type TextFile.
I get this before compiling.

My TextFile extends JPanel

This post has been edited by novakasss: 01 April 2013 - 10:31 AM

Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Too wide window

Posted 01 April 2013 - 10:59 AM

Yiou ave too many fffff and not enough rrrrr
setPreferredSize
Was This Post Helpful? 0
  • +
  • -

#12 novakasss  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 352
  • Joined: 11-July 12

Re: Too wide window

Posted 02 April 2013 - 11:24 AM

View Postpbl, on 01 April 2013 - 10:59 AM, said:

Yiou ave too many fffff and not enough rrrrr
setPreferredSize

LOL. This is sick fail. I made this preferred size for JScrollPane. Cause it contains that JTextArea. Works fine now. Thanks.
Edit: I can't add +rep. I don't know why. When I press plus button it imediately takes me to the top of the page.

This post has been edited by novakasss: 02 April 2013 - 11:25 AM

Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Too wide window

Posted 02 April 2013 - 01:39 PM

+1 seems a common problem today. The Admins should fix it soon.
I can beleive that I missed a +1 that farrell2k wanted to give me in another post >_<
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1