Jogl Applet Problems - Java Applet Development

I'm trying to write a applet that has a jogl window but for some reason my variables become null or zero when i get into the display function. I do most of my OpenGL is C++ and my JAVA isn't great but I was hoping to make a simple app and put it online. Any help is appreciated.
import java.applet.Applet;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class ElementLearner extends Applet implements GLEventListener {
     private static final long serialVersionUID = 1L;
     public double a, e, i, w, ra, theta;
     public Vector3d pos, vel;
     public double mu = 398600.5;
     
     JSlider aSlider, eSlider, iSlider, wSlider, raSlider, thetaSlider;
     Label aLabelValue, eLabelValue, iLabelValue, wLabelValue, raLabelValue, thetaLabelValue;
     
     public void init()
     {       
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);
        GLCanvas canvas = new GLCanvas(caps);
       
        canvas.setSize(400, 400);
        canvas.setVisible(true);
       
        canvas.addGLEventListener(new ElementLearner());
       
        pos = new Vector3d();
        vel = new Vector3d();
       
          a = 7378;
          e = 0;
          i = 0;
          w = 0;
          ra = 0;
          theta = 0;
          
        GridBagLayout gridbag = new GridBagLayout();
          GridBagConstraints c = new GridBagConstraints();
          c.fill = GridBagConstraints.CENTER;
        setLayout(gridbag);
       
          aSlider = new JSlider();
          aSlider.setValue((int) a);
          aSlider.setMaximum(10000);
          aSlider.setMinimum(6378);
          aSlider.addChangeListener(new MyChangeAction());
          
          eSlider = new JSlider();
          eSlider.setValue((int) e);
          eSlider.setMaximum(100);
          eSlider.setMinimum(0);
          eSlider.addChangeListener(new MyChangeAction());
          
          iSlider = new JSlider();
          eSlider.setValue((int) i);
          iSlider.setMaximum(180);
          iSlider.setMinimum(0);
          iSlider.addChangeListener(new MyChangeAction());
          
          wSlider = new JSlider();
          eSlider.setValue((int) w);
          wSlider.setMaximum(360);
          wSlider.setMinimum(0);
          wSlider.addChangeListener(new MyChangeAction());
          
          raSlider = new JSlider();
          eSlider.setValue((int) ra);
          raSlider.setMaximum(360);
          raSlider.setMinimum(0);
          raSlider.addChangeListener(new MyChangeAction());
          
          thetaSlider = new JSlider();
          eSlider.setValue((int) theta);
          thetaSlider.setMaximum(360);
          thetaSlider.setMinimum(0);
          thetaSlider.addChangeListener(new MyChangeAction());
          
          
          Label aLabel = new Label("Semi-Major Axis");
          c.gridx = 0;
          c.gridy = 0;
          gridbag.setConstraints(aLabel, c);
          add(aLabel);
          aLabelValue = new Label(Double.toString(a));
          c.gridx = 1;
          c.gridy = 0;
          gridbag.setConstraints(aLabelValue, c);
          add(aLabelValue);
          c.gridx = 2;
          c.gridy = 0;
          gridbag.setConstraints(aSlider, c);
          add(aSlider);
          
          Label eLabel = new Label("Eccentricity");
          c.gridx = 0;
          c.gridy = 1;
          gridbag.setConstraints(eLabel, c);
          add(eLabel);
          eLabelValue = new Label(Double.toString(e/100));
          c.gridx = 1;
          c.gridy = 1;
          gridbag.setConstraints(eLabelValue, c);
          add(eLabelValue);
          c.gridx = 2;
          c.gridy = 1;
          gridbag.setConstraints(eSlider, c);
          add(eSlider);
          
          Label iLabel = new Label("Inclination");
          c.gridx = 0;
          c.gridy = 2;
          gridbag.setConstraints(iLabel, c);
          add(iLabel);
          iLabelValue = new Label(Double.toString(i));
          c.gridx = 1;
          c.gridy = 2;
          gridbag.setConstraints(iLabelValue, c);
          add(iLabelValue);
          c.gridx = 2;
          c.gridy = 2;
          gridbag.setConstraints(iSlider, c);
          add(iSlider);
          
          Label wLabel = new Label("Argument of Perigee");
          c.gridx = 0;
          c.gridy = 3;
          gridbag.setConstraints(wLabel, c);
          add(wLabel);
          wLabelValue = new Label(Double.toString(w));
          c.gridx = 1;
          c.gridy = 3;
          gridbag.setConstraints(wLabelValue, c);
          add(wLabelValue);
          c.gridx = 2;
          c.gridy = 3;
          gridbag.setConstraints(wSlider, c);
          add(wSlider);
          
          Label raLabel = new Label("Right Ascencion");
          c.gridx = 0;
          c.gridy = 4;
          gridbag.setConstraints(raLabel, c);
          add(raLabel);
          raLabelValue = new Label(Double.toString(ra));
          c.gridx = 1;
          c.gridy = 4;
          gridbag.setConstraints(raLabelValue, c);
          add(raLabelValue);
          c.gridx = 2;
          c.gridy = 4;
          gridbag.setConstraints(raSlider, c);
          add(raSlider);
          
          Label thetaLabel = new Label("True Anomaly");
          c.gridx = 0;
          c.gridy = 5;
          gridbag.setConstraints(thetaLabel, c);
          add(thetaLabel);
          thetaLabelValue = new Label(Double.toString(theta));
          c.gridx = 1;
          c.gridy = 5;
          gridbag.setConstraints(thetaLabelValue, c);
          add(thetaLabelValue);
          c.gridx = 2;
          c.gridy = 5;
          gridbag.setConstraints(thetaSlider, c);
          add(thetaSlider);
          
          c.gridx = 0;
          c.gridy = 6;
          c.gridwidth = 3;
          gridbag.setConstraints(canvas, c);
          add(canvas);
          
          aSlider.setValue((int) a);
          eSlider.setValue(0);
          iSlider.setValue(0);
          wSlider.setValue(0);
          raSlider.setValue(0);
          thetaSlider.setValue(0);
          
          this.start();
          double asdf = 5;
     }
     public class MyChangeAction implements ChangeListener {
          #Override
          public void stateChanged(ChangeEvent arg0) {
               a = aSlider.getValue();
               e = ((double)eSlider.getValue())/100;
               i = iSlider.getValue();
               w = wSlider.getValue();
               ra = raSlider.getValue();
               theta = thetaSlider.getValue();
               
               aLabelValue.setText(Double.toString(a));
               eLabelValue.setText(Double.toString(e));
               iLabelValue.setText(Double.toString(i));
               wLabelValue.setText(Double.toString(w));
               raLabelValue.setText(Double.toString(ra));
               thetaLabelValue.setText(Double.toString(theta));
               
               //convertKep2Cart();
          }
     }
     #Override
     public void display(GLAutoDrawable arg0) {
        GL2 gl = arg0.getGL().getGL2();
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        // draw a triangle filling the window
        gl.glBegin(GL.GL_LINE_LOOP);
        gl.glColor3f(1, 0, 0);
       
        double lastX = pos.x;
        double lastY = pos.y;
        double lastZ = pos.z;
       
        double tempTheta = theta;
        for (i = 1; i < 360; i++)
        {
             theta = i;
             //convertKep2Cart();
             gl.glVertex3d(lastX, lastY, lastZ);
             gl.glVertex3d(pos.x, pos.y, pos.z);
        }
        theta = tempTheta;
        gl.glEnd();
     }
     #Override
     public void dispose(GLAutoDrawable arg0) {
          // TODO Auto-generated method stub
          
     }
     #Override
     public void init(GLAutoDrawable arg0) {
          // TODO Auto-generated method stub
          
     }
     #Override
     public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
               int arg4) {
          // TODO Auto-generated method stub
          
     }
} 

p0pes wrote:
..my JAVA isn't great It is Java, not JAVA. ;)
..but I was hoping to make a simple app and put it online. ..The simplest way would be to use [Java Web Start|http://www.java.com/en/download/faq/java_webstart.xml] *(<- link)* to launch a conventional JFrame. Works direct from web sites, and a lot less trouble than applets.

Related

Font chooser?

I'd like to allow my users to select their font. So my question is: is there kind of a "JFontChooser" that already existed or will I have to create my own?
I've written this one some time ago. The code is not very good and there may be several minor (?) bugs. But maybe you can use it.
Hope that helps,
Michael
import java.io.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
/** dialog class for selecting fonts
* it can real-time detect the available system fonts and display them
*
* FIXME: UNDERLINE/CROSSOUT missing
*/
public class JFontChooser extends JDialog implements ActionListener, KeyListener{
     private Object owner;
     private JLabel previewLabel;
     private JComboBox comboBoxFontNames;
     private JComboBox comboBoxFontSizes;
     private JCheckBox checkBoxBold;
     private JCheckBox checkBoxItalic;
     private String currentFontName;
     private int currentFontSize;
     private int currentFontStyle;
     private String returnState;
     public static final String BUTTONOK = "buttonOk";
     public static final String BUTTONCANCEL = "buttonCancel";
     private static final String CHANGE_FONTNAME = "changeFontName";
     private static final String CHANGE_FONTSIZE = "changeFontSize";
     private static final String CHANGE_BOLD = "changeBold";
     private static final String CHANGE_ITALIC = "changeItalic";
     private static final String DEFAULT_PREVIEW_STRING = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG";
     private String previewString = DEFAULT_PREVIEW_STRING;
     /** default constructor */
     public JFontChooser(){
     }
     public JFontChooser(Frame owner, String title, boolean modal){
          super(owner, title, modal);
          this.owner = owner;
          buildGUI();
     }
     public JFontChooser(Dialog owner, String title, boolean modal){
          super(owner, title, modal);
          this.owner = owner;
          buildGUI();
     }
     private void buildGUI(){
          this.addKeyListener(this);
          currentFontName = "Times New Roman";
          currentFontSize = 10;
          currentFontStyle = Font.PLAIN;
          // get all names of available fonts
          Vector fontItems = new Vector();
          GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
          Font fonts[] = graphicsEnvironment.getAllFonts();
          for(int i=0; i<fonts.length; i++)
               fontItems.add(fonts.getFontName());
          // create a vector of possible sizes
          Vector sizeItems = new Vector();
          for(int i=5; i<=25; i++)
               sizeItems.add(Integer.toString(i));
          // create "high-level" objects
          JLabel labelFontName = new JLabel("Font:");
          comboBoxFontNames = new JComboBox(fontItems);
          JLabel labelFontSize = new JLabel("Font Size:");
          comboBoxFontSizes = new JComboBox(sizeItems);
          checkBoxBold = new JCheckBox("Bold", false);
          checkBoxItalic = new JCheckBox("Italic", false);
          previewLabel = new JLabel(previewString);
          previewLabel.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(), "Preview"));
          JButton buttonOk = new JButton("OK");
          JButton buttonCancel = new JButton("Cancel");
          // set listeners and commands for "high-level" objects
          comboBoxFontNames.addActionListener(this);
          comboBoxFontNames.setActionCommand(CHANGE_FONTNAME);
          comboBoxFontSizes.addActionListener(this);
          comboBoxFontSizes.setActionCommand(CHANGE_FONTSIZE);
          checkBoxBold.addActionListener(this);
          checkBoxBold.setActionCommand(CHANGE_BOLD);
          checkBoxItalic.addActionListener(this);
          checkBoxItalic.setActionCommand(CHANGE_ITALIC);
          buttonOk.addActionListener(this);
          buttonOk.setActionCommand(BUTTONOK);
          buttonCancel.addActionListener(this);
          buttonCancel.setActionCommand(BUTTONCANCEL);
          Container cPane = getContentPane();
          GridBagConstraints c = new GridBagConstraints();
          // create layout for content pane
          GridBagLayout layoutCPane = new GridBagLayout();
          cPane.setLayout(layoutCPane);
          // create layouts for "sub-panels"
          GridBagLayout layoutFontPanel = new GridBagLayout();
          GridBagLayout layoutStylePanel = new GridBagLayout();
          GridBagLayout layoutButtonPanel = new GridBagLayout();
          // create panels
          JPanel fontPanel = new JPanel(layoutFontPanel);
          JPanel stylePanel = new JPanel(layoutStylePanel);
          JPanel buttonPanel = new JPanel(layoutButtonPanel);
          fontPanel.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(), "Font"));
          //stylePanel.setBackground(Color.green);
          stylePanel.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(), "Styles"));
          //buttonPanel.setBackground(Color.green);
          // set constraints for "high-level" objects and "sub-panes"
          c.gridx = 0;
          c.gridy = 0;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.weightx = 0;
          c.weighty = 0;
          c.anchor = GridBagConstraints.WEST;
          c.fill = GridBagConstraints.NONE;
          layoutFontPanel.setConstraints(labelFontName, c);
          c.gridx = 1;
          c.gridy = 0;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.weightx = 1;
          c.weighty = 0;
          c.anchor = GridBagConstraints.WEST;
          c.fill = GridBagConstraints.NONE;
          layoutFontPanel.setConstraints(comboBoxFontNames, c);
          c.gridx = 0;
          c.gridy = 1;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.weightx = 0;
          c.weighty = 0;
          c.anchor = GridBagConstraints.WEST;
          c.fill = GridBagConstraints.NONE;
          layoutFontPanel.setConstraints(labelFontSize, c);
          c.gridx = 1;
          c.gridy = 1;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.weightx = 1;
          c.weighty = 0;
          c.anchor = GridBagConstraints.WEST;
          c.fill = GridBagConstraints.NONE;
          layoutFontPanel.setConstraints(comboBoxFontSizes, c);
          c.gridx = 0;
          c.gridy = 0;
          c.gridwidth = 2;
          c.gridheight = 1;
          c.weightx = 1;
          c.weighty = 0;
          c.anchor = GridBagConstraints.WEST;
          c.fill = GridBagConstraints.BOTH;
          layoutCPane.setConstraints(fontPanel, c);
          c.gridx = 0;
          c.gridy = 0;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.weightx = 1;
          c.weighty = 0;
          c.anchor = GridBagConstraints.WEST;
          c.fill = GridBagConstraints.NONE;
          layoutStylePanel.setConstraints(checkBoxBold, c);
          c.gridx = 0;
          c.gridy = 1;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.weightx = 1;
          c.weighty = 0;
          c.anchor = GridBagConstraints.WEST;
          c.fill = GridBagConstraints.NONE;
          layoutStylePanel.setConstraints(checkBoxItalic, c);
          c.gridx = 0;
          c.gridy = 3;
          c.gridwidth = 2;
          c.gridheight = 1;
          c.weightx = 0;
          c.weighty = 0;
          c.anchor = GridBagConstraints.WEST;
          c.fill = GridBagConstraints.BOTH;
          layoutCPane.setConstraints(stylePanel, c);
          c.gridx = 0;
          c.gridy = 4;
          c.gridwidth = 2;
          c.gridheight = 1;
          c.weightx = 0;
          c.weighty = 0;
          c.anchor = GridBagConstraints.WEST;
          c.fill = GridBagConstraints.NONE;
          layoutCPane.setConstraints(previewLabel, c);
          c.gridwidth = 1;
          c.gridheight = 1;
          c.gridx = 1;
          c.gridy = 5;
          c.weightx = 1;
          c.weighty = 0;
          c.anchor = GridBagConstraints.EAST;
          c.fill = GridBagConstraints.NONE;
          c.insets = new Insets(8,0,4,4);
          //c.insets = new Insets(0,0,0,0);
          layoutCPane.setConstraints(buttonPanel, c);
          fontPanel.add(labelFontName);
          fontPanel.add(comboBoxFontNames);
          fontPanel.add(labelFontSize);
          fontPanel.add(comboBoxFontSizes);
          stylePanel.add(checkBoxBold);
          stylePanel.add(checkBoxItalic);
          buttonPanel.add(buttonOk);
          buttonPanel.add(buttonCancel);
          cPane.add(fontPanel);
          cPane.add(stylePanel);
          cPane.add(previewLabel);
          cPane.add(buttonPanel);
          pack();
     }
     /** returns if bold style was selected */
     public boolean isBold(){
          return ((currentFontStyle & Font.BOLD) == Font.BOLD);
     }
     /** returns if italic style was selected */
     public boolean isItalic(){
          return ((currentFontStyle & Font.ITALIC) == Font.ITALIC);
     }
     /** returns the currently selected font name */
     public String getFontName(){
          return currentFontName;
     }
     /** returns the currently selected font size */
     public int getFontSize(){
          return currentFontSize;
     }
     /** returns the currently selected font style */
     public int getFontStyle(){
          return currentFontStyle;
     }
     /** here you can get the return state of the dialog.
     * JFontChooser.BUTTONOK means that the ok button was pressed
     * JFontChooser.BUTTONCANCEL means that the cancel button was pressed
     */
     public String getReturnState(){
          return returnState;
     }
     /** sets the current font name */
     public void setFontName(String fontName){
          currentFontName = fontName;
          comboBoxFontNames.setSelectedItem(fontName);
          previewLabel.setFont(new Font(currentFontName, currentFontStyle, currentFontSize));
     }
     /** sets the current font size */
     public void setFontSize(int fontSize){
          currentFontSize = fontSize;
          comboBoxFontSizes.setSelectedItem(Integer.toString(fontSize));
          previewLabel.setFont(new Font(currentFontName, currentFontStyle, currentFontSize));
     }
     /** sets the current font style */
     public void setFontStyle(int fontStyle){
          currentFontStyle = fontStyle;
          if((currentFontStyle & Font.BOLD)==Font.BOLD)
               checkBoxBold.setSelected(true);
          else
               checkBoxBold.setSelected(false);
          if((currentFontStyle & Font.ITALIC)==Font.ITALIC)
               checkBoxItalic.setSelected(true);
          else
               checkBoxItalic.setSelected(false);
          previewLabel.setFont(new Font(currentFontName, currentFontStyle, currentFontSize));
     }
public void actionPerformed(ActionEvent e){
String cmd = e.getActionCommand();
boolean fontChange = false;
if(cmd.equals(CHANGE_BOLD)){
if(((JCheckBox)e.getSource()).isSelected())
currentFontStyle |= Font.BOLD;
else
currentFontStyle &= (~Font.BOLD);
fontChange = true;
}
if(cmd.equals(CHANGE_ITALIC)){
if(((JCheckBox)e.getSource()).isSelected())
currentFontStyle |= Font.ITALIC;
else
currentFontStyle &= (~Font.ITALIC);
fontChange = true;
}
if(cmd.equals(CHANGE_FONTNAME)){
currentFontName = (String)((JComboBox)e.getSource()).getSelectedItem();
fontChange = true;
}
if(cmd.equals(CHANGE_FONTSIZE)){
String currentFontSizeString = (String)((JComboBox)e.getSource()).getSelectedItem();
currentFontSize = Integer.parseInt(currentFontSizeString);
fontChange = true;
}
if(fontChange){
previewLabel.setFont(new Font(currentFontName, currentFontStyle, currentFontSize));
}
if(cmd.equals(BUTTONOK)){
this.hide();
this.returnState = BUTTONOK;
}
if(cmd.equals(BUTTONCANCEL)){
this.hide();
this.returnState = BUTTONCANCEL;
}
}
     public void keyTyped(KeyEvent e){
     }
     public void keyPressed(KeyEvent e){
          int keyCode = e.getKeyCode();
          if(keyCode == KeyEvent.VK_ESCAPE){
               actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, BUTTONCANCEL));
          }
     }
     public void keyReleased(KeyEvent e){
     }
     public static void main(String args[]){
          // we need a frame or a dialog as the fontchooser's parent ;-)
          JFrame frame = new JFrame("silly title");
          frame.pack();
          frame.setVisible(true);
          // create font chooser
          JFontChooser fontChooser = new JFontChooser((Frame)frame, "Test Font Chooser", true);
          // pre-initialize it with some values
          fontChooser.setFontName("Arial");
          fontChooser.setFontSize(20);
          fontChooser.setFontStyle(Font.ITALIC + Font.BOLD); // Font.PLAIN;
          // make it visible and wait for return thru pressed ok or cancel
          fontChooser.setVisible(true);
          // ok or cancel was pressed
          if(fontChooser.getReturnState().equals(JFontChooser.BUTTONOK)){
               // ok was pressed
               String fontName = fontChooser.getFontName();
               int fontSize = fontChooser.getFontSize();
               int fontStyle = fontChooser.getFontStyle();
          } else {
               // cancel was pressed
          }
     }
}
... i just had a look at the code again. awfully clumsy...
well, long time ago ;-) anyway, feel free to do whatever you like with it.
Michael 
I use return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); and add that to a JComboBox. I then have a custom renderer which set the font of each list entry so it shows up in its own font. It doesn't require a lot of code.
m 
Hi
Look at this:
http://forum.java.sun.com/thread.jsp?forum=57&thread=195067
Noah

Problem with JScrollPane and GridBagLayout

HI ,
I have a Jpanel with GridBag Layout.
I'm adding a JScrollPane to it.
I'm not able to place it in exact position desired.
also , when I remove the panel (Which has scrollpane on it)
and add a new panel , I'm getting some undesired results.
Can any one help.
Here is my code.*
package myJavaProject;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;
import javax.swing.border.MatteBorder;
import java.awt.event.*;
public class Example3 implements ActionListener{
GridBagConstraints c = new GridBagConstraints();
     JFrame Frame;
     JPanel framePanel;
     JPanel framePanel2;     
     JButton tempButton;
JLabel tempLabel;
JScrollPane scrollingResult;
public Example3(String title){
     
     
Frame = new JFrame(title);
Frame.setVisible(true);
     Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
framePanel = new JPanel(new GridBagLayout());
framePanel.setBackground(Color.gray);
makeGrid(18,10,framePanel);
addButton("HOME",framePanel,1,3,3,0,20);
JTextArea resultTA = new JTextArea("This is a test", 10, 80);
scrollingResult = new JScrollPane(resultTA);
//scrollingResult.setSize(300, 400);
     
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
c.gridx = 5;
     c.gridy = 3;
     c.gridwidth = 6;
     c.gridheight = 4;
     c.ipadx = 0;
     c.ipady = 0;
     scrollingResult.revalidate();
     scrollingResult.repaint();
     framePanel.add(scrollingResult,c);
     framePanel.revalidate();
     framePanel.repaint();
     
Frame.getContentPane().add(framePanel);
Frame.pack();
}
public static void main(String[] args) {
          
     new Example3("UGC Multi Model Mapping");
}
     #Override
     public void actionPerformed(ActionEvent e) {
          // TODO Auto-generated method stub
          if (e.getActionCommand() == "HOME")
          {      
               framePanel.remove(scrollingResult);
               //framePanel.removeAll();
               framePanel.revalidate();
               framePanel.repaint();
               
               
               Frame.getContentPane().remove(framePanel);
               Frame.validate();
               Frame.repaint();
               framePanel2 = new JPanel(new GridBagLayout());
               
               //framePanel2.setLayout(new GridBagLayout());
               
               makeGrid(18,10,framePanel2);
               
               Frame.getContentPane().add(framePanel2);
               Frame.pack();
               
          }
     }
     
     public void makeGrid(int x , int y , JPanel p)
     {     
          for (int j = 1; j < y; j++){
          //pageHeight;
               for (int i = 0; i < x; i = i+1)
               {              
                    JLabel tempLabel;
                    //JLabel tempLabel1;
                    
                    tempLabel = new JLabel();
                    
                    tempLabel.setName("tempLabel"+j+i);
                    //System.out.println(tempLabel.getName());
                    
                    tempLabel.setBorder( new MatteBorder(2, 2, 2, 2, Color.BLUE) );
                    //c.fill = GridBagConstraints.HORIZONTAL;
                    c.fill = GridBagConstraints.BOTH;
                    c.weightx = 1;
               c.weighty = 1;
                    //c.weightx = 0.1;     
                    c.gridx = i;
                    c.gridy = j;
                    //c.ipady = 5;
                    //c.ipadx = 5;
                    c.ipady = 50;
                    c.ipadx = 50;
                    c.gridwidth = 1;
                    
                    p.add(tempLabel, c);
                    
               }
          }     
     }//End of method addElements()
     
     public void addButton(String buttonName , JPanel p, int x,int y ,int gw, int ix, int iy){
          tempButton = new JButton(buttonName);
          //button1.setBorder( new MatteBorder(2, 2, 2, 2, Color.BLACK) );
          c.fill = GridBagConstraints.HORIZONTAL;
     
          c.gridx = x;
          c.gridy = y;
          c.gridwidth = gw;
          c.ipadx = ix;
          c.ipady = iy;
                    
          p.add(tempButton, c);
          tempButton.addActionListener(this);
          tempButton.setActionCommand(buttonName);
     }     
     
} 
In your makeGrid method, you start the value of j at 1. So it only appears that the button and scroll pane are not in the right row because row 0 is not visible with the blue lines.
Then in your actionPerformed method, you remake the grid with your old global GridBagConstraints object; which now has a gridHeight of 4 set to it. This screws up the grid. Be careful with recycling GridBagConstraints.

Use Enter Key to jump down the

I have a 5 X 5 textfield (as example) would like when user use enter key (or tab is possible) to jump down the row, let's show it as X, Y
0, 0 Enter
0, 1 Enter
0, 2 so on....
currently the Java default behavior is
0,0 Enter 1,0 Enter 2,0 ...
What API can I contorl this behavior
Coming from VB6 background so I tried to see if JTextFields has some type of "tab index"... didn't found it at least.
KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent(); works pretty well, but is there a way to direct which one is "next"? I did found focusComponent( Comp); but not sure how I can direct the next row's textfield?
Below is my test code, if you use enter key it'll jump cross to the next textfield.
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.*;
import bank.util.Util;
public class TestJTextFields extends JPanel {
     private String[] currencyBundledLabel = { "100's", "50's", "20's", "10's", "5's", "2's", "1's", };
     private String[] currencyLooseLabel = { "100's", "50's", "20's", "10's", "5's", "2's", "1's",
               "Bait", "Mutilated" };
     private String[] coinRolledLabel = { "Dollars", "Halves", "Quarters", "Dimes", "Nicels",
               "Pennies" };
     private String[] coinLooseLabel = { "Dollars", "Halves", "Quarters", "Dimes", "Nicels",
               "Pennies", "Mutilated" };
     private GridBagConstraints gridBagConstraints = new GridBagConstraints();
     private JTextField[] fields = new JTextField[29];
     protected BigDecimal[] bdList = null;
     /**
      * Create the panel
      */
     public TestJTextFields() {
          super();
          bdList = new BigDecimal[29];
          Arrays.fill(bdList, new BigDecimal("0.00"));
          initGUI();
          
     }
     private void initGUI() {
          setLayout(new GridBagLayout());
          createLables();
          createTextField();
     }
     private void createTextField() {
          int idx = 0;
          for (int j = 0; j < 7; j++) {
               gridBagConstraints.gridx = 1;
               gridBagConstraints.gridy = j + 2;
               gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
               fields[idx] = new JTextField(bdList[idx].toString());
               
               fields[idx].addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                         KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent();
                    }
               });
               
               add(fields[idx], gridBagConstraints);
               idx++;
          }
          for (int i = 0; i < 9; i++) {
               gridBagConstraints.gridx = 3;
               gridBagConstraints.gridy = i + 2;
               gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
               fields[idx] = new JTextField();
               
               fields[idx].addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                         KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent();
                    }
               });
               
               add(fields[idx], gridBagConstraints);
               idx++;
          }
          for (int i = 0; i < 6; i++) {
               gridBagConstraints.gridx = 5;
               gridBagConstraints.gridy = i + 2;
               gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
               fields[idx] = new JTextField();
               fields[idx].addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                         KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent();
                    }
               });
               add(fields[idx], gridBagConstraints);
               idx++;
          }
          for (int i = 0; i < 7; i++) {
               gridBagConstraints.gridx = 7;
               gridBagConstraints.gridy = i + 2;
               gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
               fields[idx] = new JTextField();
               add(fields[idx], gridBagConstraints);
               idx++;
          }
     }
     private void createLables() {
          final JLabel currencyLabel = new JLabel();
          currencyLabel.setText("Currency");
          gridBagConstraints.gridwidth = 4;
          gridBagConstraints.gridy = 0;
          gridBagConstraints.gridx = 0;
          add(currencyLabel, gridBagConstraints);
          final JLabel boundledLabel = new JLabel();
          boundledLabel.setText("Boundled");
          // key to spaces
          gridBagConstraints.insets = new Insets(0, 0, 0, 25);
          gridBagConstraints.gridwidth = 1;
          gridBagConstraints.gridy = 1;
          gridBagConstraints.gridx = 1;
          add(boundledLabel, gridBagConstraints);
          final JLabel looseCurrency = new JLabel();
          looseCurrency.setText("Loose");
          gridBagConstraints.gridy = 1;
          gridBagConstraints.gridx = 3;
          add(looseCurrency, gridBagConstraints);
          final JLabel coinLabel = new JLabel();
          coinLabel.setText("Coin");
          gridBagConstraints.gridwidth = 4;
          gridBagConstraints.gridy = 0;
          gridBagConstraints.gridx = 4;
          add(coinLabel, gridBagConstraints);
          final JLabel rolledLabel = new JLabel();
          rolledLabel.setText("Rolled");
          gridBagConstraints.gridwidth = 1;
          gridBagConstraints.gridy = 1;
          gridBagConstraints.gridx = 5;
          add(rolledLabel, gridBagConstraints);
          final JLabel looseCoin = new JLabel();
          looseCoin.setText("Loose");
          gridBagConstraints.gridy = 1;
          gridBagConstraints.gridx = 7;
          add(looseCoin, gridBagConstraints);
          for (int i = 0; i < currencyBundledLabel.length; i++) {
               createGeneralGridLabel(0, i + 2, GridBagConstraints.WEST, currencyBundledLabel);
          }
          for (int i = 0; i < currencyLooseLabel.length; i++) {
               createGeneralGridLabel(2, i + 2, GridBagConstraints.WEST, currencyLooseLabel[i]);
          }
          for (int i = 0; i < coinRolledLabel.length; i++) {
               createGeneralGridLabel(4, i + 2, GridBagConstraints.WEST, coinRolledLabel[i]);
          }
          for (int i = 0; i < coinLooseLabel.length; i++) {
               createGeneralGridLabel(6, i + 2, GridBagConstraints.WEST, coinLooseLabel[i]);
          }
     }
     // for label
     private void createGeneralGridLabel(int gridX, int gridY, int anchor, String labelText) {
          JLabel tmpLabel = new JLabel();
          tmpLabel.setText(labelText);
          gridBagConstraints.anchor = anchor;
          gridBagConstraints.gridx = gridX;
          gridBagConstraints.gridy = gridY;
          add(tmpLabel, gridBagConstraints);
     }
     public static void main(String[] arg) {
          JFrame f = new JFrame();
          f.add(new TestJTextFields());
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          // f.pack();
          f.setBounds(100, 100, 600, 350);
          f.setLocationRelativeTo(null);
          f.setVisible(true);
     }
}
http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#customFocusTraversal 
oh my... thanks for the pointer. the pointis yours.

Question about GridBagConstraints

Hi,
As the title of this thread suggests, I have some issued with the GridBagConstraints. I try to set the width and height of a JPanel (that uses said GridBagConstraints), but the JPanel decides to do it in its own way. Instead of listening to my suggestion (see me setting the size of descriptionPanel in my code in the second piece of code), it sets the size of my TlsProblem to the size of the JLabel (see theDescription in MyMain) I put in it.
Here is my code. First the main:
import javax.swing.*;
import java.awt.*;
public class MyMain {
     static int WIDTH = 1280;
     static int HEIGHT = 800;
     public static void main(String[] args) {
          JFrame frame = new JFrame();
          
          Container pane = frame.getContentPane();
          frame.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setTitle("ProblemPainter");
          Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
          frame.setBounds (0, 0, dimension.width, dimension.height - 200);
          
          String theOrganization = "Organization name";
          String theDescription = "10:09:30 ERR expected string or buffer, but that is not everyting, as this problem description is extremely long. And as I am chatty, I add some more length";
          String theIdentifier = "3549";
          String theSeverity = "ERR";
          String theLink = "https://foo.domain.us/mon/index.php?fuseaction=orgtree_monitor_check.dsp_edit&mc_id=3549&org_id=17";
          String theTimeStamp = "10:09:30";
          String theCollector = "28";
          Problem problem = new Problem (theOrganization, theDescription, theIdentifier,
                    theSeverity, theLink, theTimeStamp, theCollector);
          TlsProblem tlsProblem = new TlsProblem (problem);
          frame.add(tlsProblem);
          // frame.pack();
          frame.setVisible(true);
     }
}Next the code of TlsProblem, that seems to have a life of its own:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TlsProblem extends JPanel
                            implements ActionListener {
     Problem problem;
     
     JLabel organization;
     JLabel description;
     JLabel timeStamp;
     JLabel severity;
     
     JButton status;
     JButton csd;
     JButton engineer;
     
     static int WIDTH = 1280;
     static int HEIGHT = 800;
     static int INSETS = 2;
     
     public TlsProblem (Problem theProblem) {
          problem = theProblem;
          
          organization = new JLabel("Organization: " + problem.getOrganization(), SwingConstants.LEFT);
          description = new JLabel("Description: " + problem.getDescription(), SwingConstants.LEFT);
          timeStamp = new JLabel(problem.getTimeStamp(), SwingConstants.LEFT);
          timeStamp.setAlignmentX(Component.CENTER_ALIGNMENT);
          severity = new JLabel(problem.getSeverity(), SwingConstants.LEFT);
          severity.setAlignmentX(Component.CENTER_ALIGNMENT);
          
          status = new JButton (problem.getState());
          status.setAlignmentX(SwingConstants.CENTER);
          csd = new JButton ("CSD: ");
          csd.setHorizontalAlignment(SwingConstants.LEFT);
          engineer = new JButton ("Beheer: ");
          engineer.setHorizontalAlignment(SwingConstants.LEFT);
                    
          setUp();
     }
     
     private void setUp () {
          JComponent component = createComponent();
          add(component);
          setVisible (true);
     }
     
     private JComponent createComponent () {
          JPanel panel = new JPanel();
          panel.setBackground(Color.WHITE);
          panel.setSize(WIDTH, HEIGHT/10);
          logState ("createComponent: panel has dimension " + panel.getSize());
          panel.setLayout(new GridBagLayout());
          panel.setBorder(BorderFactory.createRaisedBevelBorder());
          GridBagConstraints constraints = new GridBagConstraints();
          
          // Organization name. Fill up available space horizontal
          constraints.fill = GridBagConstraints.HORIZONTAL;
          constraints.gridx = 0;
          constraints.gridy = 0;
          constraints.gridheight = 1;
          constraints.gridwidth = 2; // Take up 2 columns of space
          panel.add(organization, constraints);
          
          // Description of the problem. Fill up space both horizontal and vertical
          JPanel descriptionPanel = new JPanel();
          descriptionPanel.setOpaque(false);
          descriptionPanel.setSize(WIDTH/4, HEIGHT/10);
          logState ("createComponent: descriptionPanel has dimension " + descriptionPanel.getSize());
          constraints.fill = GridBagConstraints.BOTH;
          constraints.gridx = 0;
          constraints.gridy = 1;
          constraints.gridwidth = 2;
          constraints.gridheight = 2;// Take up 2 rows of space
          descriptionPanel.add(description);
          panel.add(descriptionPanel, constraints);
          logState ("createComponent: panel has dimension " + panel.getSize());
          
          // Time stamp of creation of the problem
          constraints.fill = GridBagConstraints.HORIZONTAL;
          constraints.gridx = 3;
          constraints.gridy = 0;
          constraints.gridwidth = 1;
          constraints.gridheight = 1;
          panel.add(timeStamp, constraints);
          
          // Severity of the problem
          constraints.gridx = 3;
          constraints.gridy = 1;
          constraints.gridwidth = 1;
          constraints.gridheight = 1;
          panel.add(severity, constraints);
          
          // Status of the problem
          constraints.gridx = 3;
          constraints.gridy = 2;
          constraints.gridwidth = 1;
          constraints.gridheight = 1;
          panel.add(status, constraints);
          
          // CSD engineer following the problem
          constraints.gridx = 4;
          constraints.gridy = 0;
          constraints.gridwidth = 1;
          constraints.gridheight = 1;
          panel.add(csd, constraints);
          // Administrator engineer following the problem
          constraints.gridx = 4;
          constraints.gridy = 1;
          constraints.gridwidth = 1;
          constraints.gridheight = 1;
          panel.add(engineer, constraints);
          
          return panel;
     }
     
     public void actionPerformed(ActionEvent event) {
          String command = event.getActionCommand();
     }
     
     public void logState (String text) {
          System.out.println ("TlsProblem." + text);
     }
}public class Problem extends JPanel {
     private String organization;
     private String description;
     private String identifier;
     private String link;
     private String severity;
     private String state;
     private String timeStamp;
     private String collector;
     private int width;
     private int height;
     public Problem (String theOrganization, String theDescription, String theIdentifier,
               String theSeverity, String theLink, String theTimeStamp, String theCollector) {
          organization = theOrganization;
          description  = theDescription;
          identifier   = theIdentifier;
          severity     = theSeverity;
          link         = theLink;
          timeStamp    = theTimeStamp;
          collector    = theCollector;
          state = NEW;
     }
     
     public String getOrganization () {
          return organization;
     }
     public String getDescription () {
          return description;
     }
     public String getIdentifier () {
          return identifier;
     }
     public String getSeverity () {
          return severity;
     }
     
     public String getState () {
          return state;
     }
     public String getTimeStamp () {
          return timeStamp;
     }
     public String getCollector () {
          return collector;
     }
     public String getLink () {
          return link;
     }
}What do I need to change in this code so I can set the size of the elements of my TlsProblem to my hearths content?
TIA
Abel 
class TlsProblem extends JPanel  implements ActionListener {
...
    static int WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
    static int HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;
...
    private JComponent createComponent() {
        JPanel panel = new JPanel();
        panel.setBackground(Color.WHITE);
        panel.setPreferredSize(new Dimension(WIDTH-20, HEIGHT / 5));
        logState("createComponent: panel has dimension " + panel.getPreferredSize());
        panel.setLayout(new GridBagLayout());
        panel.setBorder(BorderFactory.createRaisedBevelBorder());
        GridBagConstraints constraints = new GridBagConstraints();
        // Organization name. Fill up available space horizontal
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.gridheight = 1;
        constraints.gridwidth = 2; // Take up 2 columns of space
        constraints.weightx = constraints.gridwidth;
        constraints.weighty = constraints.gridheight;
        panel.add(organization, constraints);
        // Description of the problem. Fill up space both horizontal and vertical
        JPanel descriptionPanel = new JPanel();
        descriptionPanel.setOpaque(false);
        descriptionPanel.setPreferredSize(new Dimension(WIDTH / 2, HEIGHT / 10));
        logState("createComponent: descriptionPanel has dimension " + descriptionPanel.getPreferredSize());
        constraints.fill = GridBagConstraints.BOTH;
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.gridwidth = 2;
        constraints.gridheight = 2;// Take up 2 rows of space
        constraints.weightx = constraints.gridwidth;
        constraints.weighty = constraints.gridheight;
        description.setPreferredSize(descriptionPanel.getPreferredSize());
        description.setText("<html>"+description.getText());
        descriptionPanel.add(description);
        panel.add(descriptionPanel, constraints);
        logState("createComponent: panel has dimension " + panel.getPreferredSize());
        // Time stamp of creation of the problem
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridx = 3;
        constraints.gridy = 0;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.weightx = constraints.gridwidth;
        constraints.weighty = constraints.gridheight;
        panel.add(timeStamp, constraints);
        // Severity of the problem
        constraints.gridx = 3;
        constraints.gridy = 1;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.weightx = constraints.gridwidth;
        constraints.weighty = constraints.gridheight;
        panel.add(severity, constraints);
        // Status of the problem
        constraints.gridx = 3;
        constraints.gridy = 2;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.weightx = constraints.gridwidth;
        constraints.weighty = constraints.gridheight;
        panel.add(status, constraints);
        // CSD engineer following the problem
        constraints.gridx = 4;
        constraints.gridy = 0;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.weightx = constraints.gridwidth;
        constraints.weighty = constraints.gridheight;
        panel.add(csd, constraints);
        // Administrator engineer following the problem
        constraints.gridx = 4;
        constraints.gridy = 1;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.weightx = constraints.gridwidth;
        constraints.weighty = constraints.gridheight;
        panel.add(engineer, constraints);
        return panel;
    }
...
} 
Thanks.

Need to (re)paint faster

Is there a way to repaint this AWT applet of mine little bit faster? If I have 10 columns and 20 rows of textFields, when I repaint the applet, I can literally "see" the repainting being done, like an unseen hand sweeping clean the fields and then another hand putting the new fields in places. I will need to do better.
Does anyone have an advice?
Thank you.
import java.applet.Applet;
import java.awt.*;                           
import java.awt.event.*;
public class Test1112 extends Applet {
     int no_of_rec = 0;
     int index = 0;
     
     TextField[] txtDataRowDisplay1;
     TextField[] txtDataRowDisplay2;
     TextField[] txtDataRowDisplay3;
     TextField[] txtDataRowDisplay4;
     TextField[] txtDataRowDisplay5;
     TextField[] txtDataRowDisplay6;
     TextField[] txtDataRowDisplay7;
     TextField[] txtDataRowDisplay8;
     TextField[] txtDataRowDisplay9;
     TextField[] txtDataRowDisplay10;
     
     
     String[] data;
     Panel p1;
     GridBagConstraints c1;
     Panel pMain;
     Color pnlBgColor = new Color(144, 196, 222);
     
     Panel cPanel;
     
     public void init(){
          
          data = getData(index);
          no_of_rec = data.length;
          
          //main Panel
          pMain = new Panel();
          pMain.setLayout(new GridBagLayout());
          GridBagConstraints c  = new GridBagConstraints();
          pMain.setBackground(pnlBgColor);
          
          //p0
          Panel p0 = new Panel();
          p0.setLayout(new GridBagLayout());
          GridBagConstraints c0  = new GridBagConstraints();
          c0.fill = GridBagConstraints.HORIZONTAL;
          p0.setBackground(pnlBgColor);
          
          //p1
          p1 = new Panel();
          p1.setLayout(new GridBagLayout());
          c1  = new GridBagConstraints();
          
          
          Button btnNext = new Button("Next Item");
          c0.insets = new Insets(0, 0, 10, 0);
          c0.gridx = 3;
          c0.gridy = 0;
          p0.add(btnNext, c0);
          
          btnNext.addActionListener(
               new ActionListener() {
                    public void actionPerformed(ActionEvent e){
                         index++;     
                         data = getData(index);
                         no_of_rec = data.length;
                         
                         p1.removeAll();     
                         addDataPanel(p1, c1);     
                         display(data);     
                         
                         p1.invalidate();     
                         p1.validate();     
                         p1.repaint();
                         
                    }               
          });
          
          //call a method to add data row(s)
          addDataPanel(p1, c1);
          
          //add p0 and p1 to pMain;
          c.gridx = 0;
          c.gridy = 0;
          pMain.add(p0, c);
          
          c.gridx = 0;
          c.gridy = 1;
          pMain.add(p1, c);
          
          
          //p2
          Panel p2 = new Panel();
          p2.setLayout(new GridBagLayout());
          GridBagConstraints c2  = new GridBagConstraints();
          c2.fill = GridBagConstraints.HORIZONTAL;
          p2.setBackground(pnlBgColor);
          
          c.gridx = 0;
          c.gridy = 2;
          pMain.add(p2, c);
     
          display(data);
          
          add(pMain);
          
          this.setBackground(pnlBgColor);
     }//init
     
     private String[] getData(int i){
          
          int n = 0;
          if((i%2) == 0) n= 20;
          else n= 18;
          String[] data = new String[n];
          for(int j=0; j < data.length; j++){
               data[j] = "000000" + String.valueOf(j);
          }
          return data;
     }
     
    private void addDataPanel(Panel p1, GridBagConstraints c1){
          txtDataRowDisplay1 = new TextField[no_of_rec];
          txtDataRowDisplay2 = new TextField[no_of_rec];
          txtDataRowDisplay3 = new TextField[no_of_rec];
          txtDataRowDisplay4 = new TextField[no_of_rec];
          txtDataRowDisplay5 = new TextField[no_of_rec];
          txtDataRowDisplay6 = new TextField[no_of_rec];
          txtDataRowDisplay7 = new TextField[no_of_rec];
          txtDataRowDisplay8 = new TextField[no_of_rec];
          txtDataRowDisplay9 = new TextField[no_of_rec];
          txtDataRowDisplay10 = new TextField[no_of_rec];
          
          //initialize fields
          for(int i = 0; i < no_of_rec; i++){
               txtDataRowDisplay1[i] = new TextField(5);
               txtDataRowDisplay2[i] = new TextField(5);
               txtDataRowDisplay3[i] = new TextField(5);
               txtDataRowDisplay4[i] = new TextField(5);
               txtDataRowDisplay5[i] = new TextField(5);
               txtDataRowDisplay6[i] = new TextField(5);
               txtDataRowDisplay7[i] = new TextField(5);
               txtDataRowDisplay8[i] = new TextField(5);
               txtDataRowDisplay9[i] = new TextField(5);
               txtDataRowDisplay10[i] = new TextField(5);
               
          }
          
          int cnt = 0;
          for(int m = 0; m < txtDataRowDisplay1.length; m++ ){
               
               c1.gridy = m + cnt;
               
               c1.gridx = 0;
               p1.add(txtDataRowDisplay1[m], c1);
               
               c1.gridx = 1;
               p1.add(txtDataRowDisplay2[m], c1);
               
               c1.gridx = 2;
               p1.add(txtDataRowDisplay3[m], c1);
               
               c1.gridx = 3;
               p1.add(txtDataRowDisplay4[m], c1);
               
               c1.gridx = 4;
               p1.add(txtDataRowDisplay5[m], c1);
               
               c1.gridx = 5;
               p1.add(txtDataRowDisplay6[m], c1);
               
               c1.gridx = 6;
               p1.add(txtDataRowDisplay7[m], c1);
               
               c1.gridx = 7;
               p1.add(txtDataRowDisplay8[m], c1);
               
               c1.gridx = 8;
               p1.add(txtDataRowDisplay9[m], c1);
               
               c1.gridx = 9;
               p1.add(txtDataRowDisplay10[m], c1);
                    
               cnt++;
          }
          
    }
     
     private void display(String[] data){
          for(int i = 0; i < data.length; i++){
               txtDataRowDisplay1.setText(data[i]);
               txtDataRowDisplay2[i].setText(data[i]);
               txtDataRowDisplay3[i].setText(data[i]);
               txtDataRowDisplay4[i].setText(data[i]);
               txtDataRowDisplay5[i].setText(data[i]);
               txtDataRowDisplay6[i].setText(data[i]);
               txtDataRowDisplay7[i].setText(data[i]);
               txtDataRowDisplay8[i].setText(data[i]);
               txtDataRowDisplay9[i].setText(data[i]);
               txtDataRowDisplay10[i].setText(data[i]);
               
          }
     }
     
}
and here is the html
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM NAME="test1112">
</form>
<applet code="Test1112.class" archive="test1112.jar" WIDTH=600 HEIGHT=600>
</APPLET>
</BODY>
</HTML>
I would suggest using a JTable, it is designed to do this. It supports double buffering to produce quick redraws. It does require Swing however. 
No, cannot use Swing. 
You should be able to use your own double buffering. There might be some libraries out there to help you.
This will should ensure the user does not see the disply being drawn.

Categories

Resources