aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes ScrollBar Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ScrollBar Problem" Watch "ScrollBar Problem" New topic
Author

ScrollBar Problem

g minn
Greenhorn

Joined: Feb 19, 2003
Posts: 1
Hi iam having great difficulties with using Applets and swing for the first time.
i have an applet working, but cannot get a scrollbar working. Maybe it is because the layout is not set properly.
here is the code:
import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Enumeration;
import javax.swing.*;
public class Translator1 extends JApplet implements ActionListener {
private String myName;
private JTextField nameField;
private JTextArea status;
private String newline;
public void init() {
this.setBackground(Color.lightGray);
JScrollBar bar= new JScrollBar();

GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
getContentPane().setLayout(gridBag);

JLabel receiverLabel = new JLabel("Type Text Here:", Label.RIGHT);
gridBag.setConstraints(receiverLabel, c);
this.getContentPane().add(receiverLabel);
nameField = new JTextField(getParameter("TRANSLATIONTEXT"), 10);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.REMAINDER;
gridBag.setConstraints(nameField, c);
this.getContentPane().add(nameField);
nameField.addActionListener(this);

JButton button = new JButton("Translate Text"); //TEXT BUTTONS
c.anchor = GridBagConstraints.WEST;
c.gridwidth = GridBagConstraints.FIRST_LINE_START;
c.fill = GridBagConstraints.NONE;
gridBag.setConstraints(button, c);
this.getContentPane().add(button);
button.addActionListener(this);
button.setActionCommand("0");

JButton button1 = new JButton("Add Translations");
c.anchor = GridBagConstraints.WEST;
c.gridwidth = GridBagConstraints.FIRST_LINE_START;
gridBag.setConstraints(button1, c);
this.getContentPane().add(button1);
button1.addActionListener(this);
button1.setActionCommand("1");
JButton button2 = new JButton("List Translations");
c.anchor = GridBagConstraints.WEST;
//c.gridwidth = GridBagConstraints.RELATIVE;
gridBag.setConstraints(button2, c);
this.getContentPane().add(button2);
button2.addActionListener(this);
button2.setActionCommand("2");
JButton button3 = new JButton("Clear Text");
c.anchor = GridBagConstraints.WEST;
c.gridwidth = GridBagConstraints.REMAINDER;
gridBag.setConstraints(button3, c);
this.getContentPane().add(button3);
button3.addActionListener(this);
button3.setActionCommand("3");


status = new JTextArea();
this.getContentPane().add(bar);
status.setEditable(false);
c.anchor = GridBagConstraints.CENTER; //reset to the default
status.setBackground(Color.white); // color
status.setForeground(Color.red);
c.fill = GridBagConstraints.BOTH; //make this big
c.weightx = 1.0;
c.weighty = 1.0;
gridBag.setConstraints(status, c);
this.getContentPane().add(new JScrollPane(status));

newline = System.getProperty("line.separator");
}
:roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ScrollBar Problem