-
Text area problem
Hi
I have created some java console based programs, now I want to make a GUI that has a JTextArea inside a JScrollPane inside a JPanel. When I didn't have the JPanel it would always make the JTextArea the size of the window, but when I have them inside the JPanel, the JTextArea will stay the preferred size and the JScrollPane wouldn't work. I want to make it so I can have the JPanel and make it so that the JScrollPane is the same size as the window, and if there is too much text, the scrollbars will appear. Please help, thanks.
-
Re: Text area problem
Hi
I think the problem is with the layout manage. Are you using any layout manage here, and if so which one. JPanel by default uses FlowLayout which might not be the best fit for your purposes. Perhaps a Borderlayout is what you want, and then you can add the JScrollPane to the JPanel in the BorderLayout.CENTER position. It would be better if you post your code. so that I can check it and if possible can solve it.
-
Re: Text area problem
Hi,
Thanks for replying. I am posting my code below, go through it, if any solution the reply me back.
Code:
public class Resize extends JFrame
{
Jpal pa = new Jpal(false);
JScrollpa scrollpa;
JtxArea tx = new JtxArea(50, 80);
JTabbedpa tabbedpa = new JTabbedpa();
public Resize()
{
scrollpa = new JScrollpa(tx);
pa.add(scrollpa, BorderLayout.CENTER);
tabbedpa.addTab("Resize", null, pa, "");
add(tabbedpa);
}
public static void main( String args[] )
{
final Resize window = new Resize();
window.setSize( 1680, 1050 );
window.setVisible( true );
}
}
-
Re: Text area problem
Hi
I am posting the code. I have tried it, you see if it suits your needs.
Code:
public class Resize extends JFrame {
Jpnl pn = new Jpnl(false);
JScrollpn scrollpn;
JtxArea tx = new JtxArea(50, 80);
JTabbedpn tabbedpn = new JTabbedpn();
public Resize() {
pn.setLayout(new BorderLayout()); // set the Jpnl's layout to BorderLayout
scrollpn = new JScrollpn(tx);
pn.add(scrollpn, BorderLayout.CENTER);
tabbedpn.addTab("Resize", null, pn, "");
add(tabbedpn);
}
public static void main(String args[]) {
final Resize window = new Resize();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(1680, 1050);
window.setVisible(true);
}
}
Page generated in 1,713,901,411.79109 seconds with 11 queries