my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Simple GUI Question........... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Simple GUI Question..........." Watch "Simple GUI Question..........." New topic

Simple GUI Question...........

sam patel
Ranch Hand

Joined: Jun 13, 2002
Posts: 103
This is a simple question but i can't seem to figure it out.
For example i am using this code...
feel free to run this code...
When you run this you see the scrollbars with the Swing look (Bars look so nice)...
I am using this same type of code in my other project with JBuilder 7 and I am getting the plain look of the scrollbars.
Any suggestions will be greatly appreciated..
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
public class SimpleTableDemo extends JFrame {
private boolean DEBUG = true;
public SimpleTableDemo() {
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Angela", "Lih",
"Teaching high school", new Integer(4), new Boolean(false)}
String[] columnNames = {"First Name",
"Last Name",
"# of Years",
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this window.
getContentPane().add(scrollPane, BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
public static void main(String[] args) {
SimpleTableDemo frame = new SimpleTableDemo();
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

The quick answer is that something that calls your code is setting the look and feel to something other than Swing (Metal). If you don't see Metal L&F only when running in JBuilder, then I would think that JBuilder was setting L&F to something else. If you don't see Metal L&F when calling this code through another class, somewhere in that class, or a class that called it, some class is setting the Look & Feel to something other than Metal...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
GeeCON Prague 2014
subject: Simple GUI Question...........