• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

ScrollBar Problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic