LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-25-2004, 06:56 PM   #1
ElementNine
Member
 
Registered: Sep 2003
Distribution: Red Hat 9 or Gentoo 1.4 whatever I can get to work first
Posts: 105

Rep: Reputation: 15
JTextPane Won't Resize


Code:
	public static void main(String args[]){
	
		/*********************************************************
		*                   Set up mainFrame                     *
		*********************************************************/
		JFrame mainFrame = new JFrame(getDocName());
		windowAction wA = new windowAction();
		mainFrame.addWindowListener(wA);
		mainFrame.setLocation(400,300);
		
		/*********************************************************
		*                    Create mainPanel                    *
		*********************************************************/
		JPanel mainPanel = new JPanel();
		mainPanel.setPreferredSize(new Dimension(800,600));
		
		JTextPane mainTextPane = new JTextPane();
		mainTextPane.setPreferredSize(new Dimension(800,600));
		
		mainPanel.add(mainTextPane, BorderLayout.CENTER);
		
		/*********************************************************
		*                 Initialize mainFrame                   *
		*********************************************************/
		mainFrame.getContentPane().add(mainPanel, BorderLayout.CENTER);
		mainFrame.pack();
		mainFrame.setVisible(true);
	}
Okay theres the main method i was wondering how i get the JTextPane to resize with the window? if i dont set a preferred size its super small till i start typing and if i set the size it sticks at the size. so what do i do to make components resize to fit parts of the window
 
Old 02-26-2004, 12:06 AM   #2
chewysplace
Member
 
Registered: Sep 2003
Distribution: Slackware 10 w/ Kernel 2.6.8
Posts: 176

Rep: Reputation: 30
I had to dig for this but here you go:
http://216.239.37.104/search?q=cache...hl=en&ie=UTF-8
 
Old 02-26-2004, 02:20 AM   #3
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
If you leave out mainFrame.pack(), so it doesn't optimize the size of everything and set the mainFrame.setSize(800,600) it should have the effect you want.
 
Old 02-26-2004, 09:59 PM   #4
ElementNine
Member
 
Registered: Sep 2003
Distribution: Red Hat 9 or Gentoo 1.4 whatever I can get to work first
Posts: 105

Original Poster
Rep: Reputation: 15
yeah but my textpane doesnt resize when the window resizes i want it to fill a panel
 
Old 02-27-2004, 02:05 AM   #5
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
use a scroll pane as it's container

Code:
		...
               
		mainFrame.setLocation(400,300);
		mainFrame.setSize(800,600);
	
		JTextPane mainTextPane = new JTextPane();
		JScrollPane mainPanel = new JScrollPane(mainTextPane);

		mainFrame.getContentPane().add(mainPanel, BorderLayout.CENTER);
		
		mainFrame.setVisible(true);
		
		...
 
Old 02-28-2004, 01:19 PM   #6
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
or give the frame's contentPane a 1x1 GridLayout if you don't want it to scroll...

Code:
mainFrame.getContentPane().setLayout(new GridLayout(1,1));
Also you don't want to put the Object into a JPanel then the contentPane, cuz that's almost the same as a JPanel inside another JPanel, and it just clutters the component hierarchy, which will slow your UI down considerably if you do it in several places. What you want to do should look like this:

Code:
	public static void main(String args[]){
		
			/*********************************************************
			*                   Set up mainFrame                     *
			*********************************************************/
			JFrame mainFrame = new JFrame("Test");
			mainFrame.setLocation(400,300);
			
			/*********************************************************
			*                    Create mainPanel                    *
			*********************************************************/
			Container mainPanel = mainFrame.getContentPane();
			
			JTextPane mainTextPane = new JTextPane();
			
/********************************************************
      This (below) could also be something like:

mainPanel.setLayout(new GridLayout(1,1));
mainPanel.add(mainTextPane);

      in which case it would not scroll if the text outgrew the component.
********************************************************/
			mainPanel.add(new JScrollPane(mainTextPane));
			
			/*********************************************************
			*                 Initialize mainFrame                   *
			*********************************************************/
			mainFrame.setSize(800,600);
			mainFrame.setVisible(true);
		}
HTH

B.

Last edited by german; 02-28-2004 at 01:39 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Monitor will not resize Drifter Linux - Hardware 2 12-01-2005 06:37 AM
how to resize mepis david waldo MEPIS 1 06-04-2005 01:12 AM
how to resize disk !!! abhigo Linux - Software 3 01-23-2005 01:59 PM
Resize / ? Sugarat Solaris / OpenSolaris 4 12-06-2003 12:10 PM
XP resize problem tincho Linux - Newbie 2 09-22-2003 07:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration