JScrollPane

thatIsAFeature

Grünschnabel
Hallo,
kann mir jemand erklären, warum im folgenden Proramme im Textfeld keine Scroll-Bar angezeigt wird
Bin für Hilfe dankbar!!


package robotworld;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;

import building.Level;
import building.Room;

import robotworld.RobotWorld2.DemoPainter;
import building.*;
import java.awt.Toolkit;



public class RobotGui extends JFrame{

private static final long serialVersionUID = -8021964675625900377L;

Container contentPane ;
JPanel jp1;
JPanel jp2;
JTextArea textArea;
JButton findTreasure, reStart, close;
JScrollPane scroller;
Eventhandler eventhandler= new Eventhandler();
DemoPainter painter;
JMenuBar jb;
JMenu jm;

{// Start Instance - Initialer
// setLayout(null);

painter = new DemoPainter();
painter.setBounds(0, 0, 650, 500);


setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("RobotWorld");
setSize(900,600);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((int)d.getWidth()/2-getSize().width/2, (int)d.getHeight()/2-getSize().height/2);
jb = new JMenuBar();
jm = new JMenu("File");
jb.add(jm);
this.setJMenuBar(jb);

contentPane = getContentPane();
//contentPane.setLayout(null); // <<<<<<---------- Das war der Fehler
contentPane.setBackground(java.awt.Color.black);


jp1 = new JPanel();
jp2 = new JPanel();

jp1.setLayout(null);
jp2.setLayout(null);


jp1.setBounds(0,500 , 900, 100);
jp2.setBounds(0,0 ,900 ,500 );
jp1.setBackground(java.awt.Color.darkGray);
jp2.setBackground(java.awt.Color.LIGHT_GRAY);

textArea = new JTextArea();
textArea.setBounds(650, 0, 250, 500);





/*JScrollPane jsp = new JScrollPane(jta);
jsp.setPreferredSize(jta.getPreferredSize());
jsp.setOpaque(true);

this.add(jsp,BorderLayout.CENTER);

*/
scroller = new JScrollPane();
scroller.getViewport().add(textArea);

jp2.add(scroller);
contentPane.add(scroller);
//scroller.setPreferredSize(textArea.getPreferredSize());
//scroller.setOpaque(true);
//scroller.setVisible(true);






// ************* Buttons **************************

findTreasure = new JButton("findTreasure");
findTreasure.setBounds(200, 20, 100, 30);
findTreasure.addActionListener(eventhandler);
//findTreasure.setVisible(true);

reStart= new JButton("reStart");
reStart.setBounds(400,20,100,30);
reStart.addActionListener(eventhandler);
//reStart.setVisible(true);

close = new JButton ("close");
close.setBounds(600,20,100,30);
close.addActionListener(eventhandler);
// close.setVisible(true);

//*************************************************




jp2.add(painter);
jp2.add(textArea);
jp1.add(findTreasure);
jp1.add(reStart);
jp1.add(close);





contentPane.add(jp1);
contentPane.add(jp2);
// contentPane.setVisible(true);


addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e) {
dispose();
}});


this.setVisible(true);

//repaint();

}// Ende Instance - Initialer









public class Eventhandler implements ActionListener{

public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source == close ) dispose();

}}// Ende Eventhandler


public static void main(String[] args) {
RobotGui gui = new RobotGui();
}


class DemoPainter extends JComponent {

// ist nicht interessant

}
 
Ich sehe kein TextFeld und auch kein JTextFeld. Du meinst sicherlich die JTextArea mit dem Namen textArea!

PS: Verwende Bitte beim nächsten mahl die
Code:
bla.bla.bla
Tags. Oder noch besser ändere dies.
 
Die Option um Code einzufügen habe ich auch gesucht, leider nicht gefunden,
wie t dass denn?
Java:
Int test;
 
Zuletzt bearbeitet von einem Moderator:
achso es t danke,
das Ganze nochmal besser:
Code:
package robotworld;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;

import building.Level;
import building.Room;

import robotworld.RobotWorld2.DemoPainter;
import building.*;
import java.awt.Toolkit;

public class RobotGui extends JFrame{
private static final long serialVersionUID = -8021964675625900377L;
Container contentPane ;
JPanel jp1;
JPanel jp2;
JTextArea textArea;
JButton findTreasure, reStart, close;
JScrollPane scroller;
Eventhandler eventhandler= new Eventhandler();
DemoPainter painter;
JMenuBar jb;
JMenu jm;
{// Start Instance - Initialer
// setLayout(null);
painter = new DemoPainter();
painter.setBounds(0, 0, 650, 500);

setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("RobotWorld");
setSize(900,600);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((int)d.getWidth()/2-getSize().width/2, (int)d.getHeight()/2-getSize().height/2);
jb = new JMenuBar();
jm = new JMenu("File");
jb.add(jm);
this.setJMenuBar(jb);

contentPane = getContentPane();
//contentPane.setLayout(null); // <<<<<<---------- Das war der Fehler
contentPane.setBackground(java.awt.Color.black);

jp1 = new JPanel();
jp2 = new JPanel();
jp1.setLayout(null);
jp2.setLayout(null);

jp1.setBounds(0,500 , 900, 100);
jp2.setBounds(0,0 ,900 ,500 );
jp1.setBackground(java.awt.Color.darkGray);
jp2.setBackground(java.awt.Color.LIGHT_GRAY);

textArea = new JTextArea();
textArea.setBounds(650, 0, 250, 500);


/*JScrollPane jsp = new JScrollPane(jta);
jsp.setPreferredSize(jta.getPreferredSize());
jsp.setOpaque(true);

this.add(jsp,BorderLayout.CENTER);

*/
scroller = new JScrollPane();
scroller.getViewport().add(textArea);

jp2.add(scroller);
contentPane.add(scroller);
//scroller.setPreferredSize(textArea.getPreferredSize());
//scroller.setOpaque(true);
//scroller.setVisible(true);


// ************* Buttons **************************

findTreasure = new JButton("findTreasure");
findTreasure.setBounds(200, 20, 100, 30);
findTreasure.addActionListener(eventhandler);
//findTreasure.setVisible(true);

reStart= new JButton("reStart");
reStart.setBounds(400,20,100,30);
reStart.addActionListener(eventhandler);
//reStart.setVisible(true);

close = new JButton ("close");
close.setBounds(600,20,100,30);
close.addActionListener(eventhandler);
// close.setVisible(true);

//*************************************************


jp2.add(painter);
jp2.add(textArea);
jp1.add(findTreasure);
jp1.add(reStart);
jp1.add(close);


contentPane.add(jp1);
contentPane.add(jp2);
// contentPane.setVisible(true);


addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e) {
dispose();
}});


this.setVisible(true);

//repaint();

}// Ende Instance - Initialer

public class Eventhandler implements ActionListener{

public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source == close ) dispose();

}}// Ende Eventhandler


public static void main(String[] args) {
RobotGui gui = new RobotGui();
}


class DemoPainter extends JComponent {

// ist nicht interessant

}
 
Zurück