Problem with AWT/Swing code

"ffileppo" <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
Hi everyone,

I'm doing some testing with AWT/Swing applications compiled with gcj 4.4 (which is using classpath 0.97.2).

I'm having some troubles with the following code; it does not show
the JComponent inside the JFrame (I've tried both on x86 and arm).

This code runs fine if compiled with OpenJDK, so I guess that this issue is more related to gcj rather then classpath.

Any thoughts or ideas?

Thank you

Francesco

Code:

import java.awt.BorderLayout;

import javax.swing.DefaultListModel;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class MainPanel extends JPanel implements ListSelectionListener {

  static final int NUM_ROWS = 500;

  JList list;
  JLabel lblSelection;
  DefaultListModel listModel;

  int startRow = 0;
  long startTime = 0;

  Runnable r = new Runnable() {
    public void run() {
      long deltaTime = System.currentTimeMillis() - startTime;
      for (int i=startRow; i<NUM_ROWS; i++) {
        listModel.set(i, ""+deltaTime);
      }

      startRow++;
      startTime = System.currentTimeMillis();

      SwingUtilities.invokeLater(r);

    }
  };

  public MainPanel() {
    super(new BorderLayout());
    listModel = new DefaultListModel();
    for (int i=0; i<NUM_ROWS; i++) {
      listModel.addElement("Element "+i);
    }

    //Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    list.addListSelectionListener(this);
    list.setVisibleRowCount(5);

    JScrollPane listScrollPane = new JScrollPane(list);

    lblSelection = new JLabel(" ");

    add(lblSelection, BorderLayout.SOUTH);
    add(listScrollPane, BorderLayout.CENTER);

    // t.start();
    startTime = System.currentTimeMillis();
    SwingUtilities.invokeLater(r);
  }

  public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting() == false) {
      if (list.getSelectedIndex() == -1) {
        //No selection
        lblSelection.setText("");
      } else {
        //Selection
        lblSelection.setText("Item selected: "+list.getSelectedIndex());
      }
    }
  }

  public static void main(String[] args) {
    //Create and set up the window.
    JFrame frame = new JFrame("TestUI #1");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the content pane.
    JComponent newContentPane = new MainPanel();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);

    //Display the window.
    frame.setBounds(10, 10, 500, 400);
    frame.setVisible(true);
  }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.