-1

Try to create testarea with scrollable .I use ScrollPane on JTextArea bit does not work I do google lots but cannot solve my problem ,I saw some solution such as this link ,but cannot solve my problem also

Here is my code

 JTextArea txtrZdsxasd = new JTextArea();
txtrZdsxasd.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
    txtrZdsxasd.setRows(8);

    txtrZdsxasd.setColumns(8);
    txtrZdsxasd.setLineWrap(true);
    txtrZdsxasd.setWrapStyleWord(true);
    JScrollPane scrollPane = new JScrollPane(txtrZdsxasd);

    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
     scrollPane.setPreferredSize(new Dimension(100,100));

I using SWT in eclipse so this is my layout

GroupLayout groupLayout = new GroupLayout(frmThermalProcessing.getContentPane());
    groupLayout.setHorizontalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(groupLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addGroup(groupLayout.createSequentialGroup()
                        .addComponent(txtrZdsxasd, GroupLayout.PREFERRED_SIZE, 966, GroupLayout.PREFERRED_SIZE)
                        .addGap(18)
                        .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 18,GroupLayout.PREFERRED_SIZE))
                    .addGroup(groupLayout.createSequentialGroup()
                        .addComponent(lblLocation)
                        .addGap(39)
                        .addComponent(lblFolderName))
                    .addComponent(btnBrowse)
                    .addGroup(groupLayout.createSequentialGroup()
                        .addComponent(btnNewButton)
                        .addGap(27)
                        .addComponent(lblSaveFileLocation)
                        .addGap(18)
                        .addComponent(lblUri)))
                .addContainerGap())
    );
    groupLayout.setVerticalGroup(
        groupLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(groupLayout.createSequentialGroup()
                .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addGroup(groupLayout.createSequentialGroup()
                        .addGap(20)
                        .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                            .addComponent(lblFolderName)
                            .addComponent(lblLocation, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))
                        .addGap(18)
                        .addComponent(btnBrowse)
                        .addPreferredGap(ComponentPlacement.RELATED)
                        .addComponent(txtrZdsxasd, GroupLayout.PREFERRED_SIZE, 283, GroupLayout.PREFERRED_SIZE)
                        .addGap(18)
                        .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                            .addComponent(btnNewButton)
                            .addComponent(lblSaveFileLocation)
                            .addComponent(lblUri)))
                    .addGroup(groupLayout.createSequentialGroup()
                        .addGap(99)
                        .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(18, Short.MAX_VALUE))
    );

What I done wrong ??? I'm not expert in java so please kindly to help me figure out

Community
  • 1
  • 1
  • *"Wanna use.."* Want to see properly spelled phrases like 'want to'. Given the international audience, it pays to avoid slang. – Andrew Thompson May 24 '14 at 02:14
  • Given the grammar I expect the asker is not a native english speaker, and might be writing his or her best. Also, in your comment's first sentance, there is no subject. That actually gave me a hard time reading the comment, as the quote also resembles your request. As an international audience member myself, that confused me more :) – jumps4fun May 28 '14 at 11:28
  • Oh, thank you for comment both of you ,sorry for my bad English ,I will improve it more. – user2968192 Jun 04 '14 at 16:12

1 Answers1

0

Maybe try changing this line:

.addComponent(txtrZdsxasd, GroupLayout.PREFERRED_SIZE, 283, GroupLayout.PREFERRED_SIZE)

with this:

.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 283, GroupLayout.PREFERRED_SIZE)

I do not have any experience with the group layout, but generally speaking, if you add a swing component into a container, it will only stay at the last place you put it. Therefor you might be removing the textarea from the scrollPane, when you directly add it into the layout container.

Also, when you later try to add your scrollPane, with: .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))) you have already removed the text area out of it.

This post might provide further information about Swing components, relevant to your issue: Can't a Swing component be added to multiple containers?

Community
  • 1
  • 1
jumps4fun
  • 3,635
  • 9
  • 45
  • 84