Forzar JScrollPane de tamaño fijo en DesignGridLayout

I want to display JTextArea with 2 visible row and 30 visible column.

package testing;

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JComboBox;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

 * @author Denni
public class TestWindow extends JFrame {
    public TestWindow() {
        this.setPreferredSize(new Dimension(700, 600));
        JDesktopPane desktopPane = new JDesktopPane();
        ModifyFrame modifyFrame = new ModifyFrame();

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TestWindow().setVisible(true);

    class ModifyFrame extends JInternalFrame {
        private JTabbedPane tabPane;
        private JPanel panel;
        private JComboBox jcb;
        private JTextArea jta;
        private JTextField jtf1;
        private JTextField jtf2;
        private JTextField jtf3;

        public ModifyFrame() {
            super("Testting", true, true, true);
        private void initComponents() {
            this.setPreferredSize(new Dimension(600,450));
            tabPane = new JTabbedPane();
            this.getContentPane().add(BorderLayout.CENTER, tabPane);
            panel = new JPanel();
            jta = new JTextArea(2, 30);
            Dimension d = jta.getPreferredSize();
            jcb = new JComboBox();
            jtf1 = new JTextField();
            jtf2 = new JTextField();
            jtf3 = new JTextField();
            JScrollPane tmp = new JScrollPane();
            DesignGridLayout layout = new DesignGridLayout(panel);
            layout.row().grid().empty().grid(new JLabel("Testing")).add(new JSeparator());
            layout.row().grid(new JLabel("jtf1")).add(jtf1).grid(new JLabel("jta")).add(tmp);
            layout.row().grid(new JLabel("jtf2")).add(jtf2).grid().spanRow();
            layout.row().grid(new JLabel("jtf3")).add(jtf3).grid(new JLabel("jcb")).add(jcb);
            tabPane.add("Tab ", panel);

With those codes, I can't make my jta viewed with 2 row and 30 column size. The JScrollPane always resize itself to more than 10rows and 50column size. But if I don't put the jta into JScrollPane, it can view with exact 2 row and 30 column size!

How to force the JScrollPane to obey the size?

preguntado el 05 de mayo de 13 a las 15:05

post a compilable code, please! -

@sgmart Don't edit his code. Make an answer where you correct it, but editing will make the mistakes unnoticable. -

@sgmart I've edited my code, I've tested it, it run flawlessly. But the jta still looks wrong. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.