Swing i autoscroll

0
        JFrame myFrame = new JFrame("Robin");
        Panel leftPanel = new Panel();
        Panel centerPanel = new Panel();
        JPanel southPanel = new JPanel();
        Button bClose = new Button("Przyciśnij mnie!");
        JTextArea taPole = new JTextArea();
        JTextField tfPole = new JTextField();
        JScrollPane pane = new JScrollPane(taPole);
        Dimension d1 = new Dimension(500, 30);
        Dimension d2 = new Dimension(500, 700);

            myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            leftPanel.add(bClose);
            centerPanel.add("Center", taPole);
            southPanel.add(tfPole);

            tfPole.setPreferredSize(d1);
            tfPole.setSize(d1);
            tfPole.setEditable(true);
            tfPole.setEnabled(true);

            southPanel.setBackground(Color.red);

            taPole.setEditable(false);
            taPole.add(pane);
            pane.setVisible(true);
            taPole.setBackground(Color.white);
            taPole.setText("Dlugi tekst");
            taPole.setPreferredSize(d2);
            taPole.setSize(taPole.getWidth(), 800);
            taPole.setPreferredSize(d2);
            taPole.setLineWrap(true);
            taPole.setWrapStyleWord(true);
            taPole.setAutoscrolls(true);
            

            bClose.setActionCommand("Wypisz");
            bClose.addActionListener(this);

            myFrame.add("West", leftPanel);
            myFrame.add("Center", centerPanel);
            myFrame.add("South", southPanel);
            myFrame.pack();
            
            Pokaz();

Niestety scrolla jak nie było tak nie ma... Może ktoś potrafi pomóc. To tylko fragment kodu, ale ten najistotniejszy...

0

Z tego co widze do JTextAre dodales JScroll pane. Robi sie odwrotnie: tworzysz JTextArea, tworzysz JScrollPane i dodajesz area do pane, i do frame/panelu dodajesz scrolla.

0

rozmiary też ustalić dla JScrollPane? czy dla JTextArea? Bo jak robie dla Area to nie wyświetla się nawet JTextArea...

0

Rozmiary ustaw dla scrolla.

0

Wszystko działa, dzięki :)

A żeby nie robić drugiego tematu to mam jeszcze jedno pytanie:
Jak ustawić kilka przycisków jeden pod drugim, jeśli wszystkie mają znajdować się w jednym panelu po lewej stronie ramki?

0

Jest wiele sposobow. Np mozesz stworzyc panel ktory ma layout ustationy na GridLayout z 3 wierszami i 1 kolumna, do niego pododawac buttony, i na koniec dodac ten panel do frame w kierunku zachod. Cos takiego:

package test;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;


public class FrameTest {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setPreferredSize(new Dimension(200, 100));
        JTextArea area = new JTextArea("Text text text text text text text text text text text "
                + "text text text text text text text text text text text text");
        area.setLineWrap(true);
        JScrollPane scroll = new JScrollPane(area);
        frame.add(scroll, BorderLayout.CENTER);
        JPanel panel = new JPanel(new GridLayout(3, 1));
        panel.add(new JButton("Top"));
        panel.add(new JButton("Middle"));
        panel.add(new JButton("Bottom"));
        frame.add(panel, BorderLayout.WEST);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

Pozdro.

0

dzięki za pomoc, działa :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1