bom dia,
Gostaria da ajuda de alguem para a seguinte situação tenho uma area de texto dentro da minha tela e gostaria de colocar uma barra de rolagem nela, sei no swt porem em swing nem sei se alguem puder me ajudar fico grato
segue meu codigo
[code] panel = new JPanel();
panel.setLayout(new BorderLayout());
JToolBar toolbar = new JToolBar();
toolbar.setFloatable(false);
final JTextArea area = new JTextArea();
area.setSelectedTextColor(Color.red);
add(area, BorderLayout.CENTER);
add(toolbar, BorderLayout.NORTH);
JToolBar vertical = new JToolBar(JToolBar.VERTICAL);
vertical.setFloatable(false);
vertical.setMargin(new Insets(10, 5, 5, 5));
ImageIcon select = new ImageIcon(getClass().getResource("computer.png"));
ImageIcon shapeed = new ImageIcon(getClass().getResource("printer.png"));
ImageIcon exit = new ImageIcon(getClass().getResource("exit.png"));
JButton bexit = new JButton(exit);
bexit.setToolTipText("Sair");
bexit.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
bexit.setBorder(new EmptyBorder(3 ,0, 3, 0));
JButton selectb = new JButton(select);
selectb.setToolTipText("Abrir arquivo");
selectb.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileopen = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("*.*", "c:/");
fileopen.addChoosableFileFilter(filter);
//FileInputStream fi = null;
int ret = fileopen.showDialog(panel, "Open file");
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fileopen.getSelectedFile();
FileInputStream fi = null;
try {
fi = new FileInputStream(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Scanner scan = new Scanner(fi);
String readLine ="";
String conteudo ="";
while (scan.hasNext()) {
readLine = scan.next();
conteudo += readLine+ "\r\n";
}
String text = conteudo.toString();
area.setText(text);
}
}
});
selectb.setBorder(new EmptyBorder(3, 0, 3, 0));
JButton shapeedb = new JButton(shapeed);
shapeedb.setToolTipText("Salvar arquivo");
shapeedb.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileopen = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("*.txt", "c:/");
fileopen.addChoosableFileFilter(filter);
int ret = fileopen.showDialog(panel, "Save File");
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fileopen.getSelectedFile();
FileOutputStream fo =null;
try {
fo = new FileOutputStream(file, false);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
fo.write(area.getText().getBytes());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
shapeedb.setBorder(new EmptyBorder(3, 0, 3, 0));
vertical.add(selectb);
vertical.add(shapeedb);
vertical.add(bexit);
add(vertical, BorderLayout.WEST);
JLabel statusbar = new JLabel("O mais novo notepad");
statusbar.setPreferredSize(new Dimension(-1, 22));
statusbar.setBorder(LineBorder.createGrayLineBorder());
add(statusbar, BorderLayout.SOUTH);
setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);[/code]