ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Red Hat 9 or Gentoo 1.4 whatever I can get to work first
Posts: 105
Rep:
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
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.
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);
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.