0
import java.awt.BorderLayout;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.text.*;


public class cl{
  public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton btn = new JButton("btn");
    frame.setLayout(null);
    btn.setBounds(550,65,100,40);

    Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
        { "Row2-Column1", "Row2-Column2", "Row2-Column3" } };
    Object columnNames[] = { "Column One", "Column Two", "Column Three" };
    JTable table = new JTable(rowData, columnNames);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(btn);
    frame.add(scrollPane);
    frame.setSize(900,600);
    frame.setVisible(true);

  }
}

I am new in java swing ..... I want to add scrollable JTable, would not use any layout that is why use I use setLayout(null). bt i can not see the table on frame how to fix it ??

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user
  • 143
  • 1
  • 8
  • 1
    Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Mar 12 '16 at 12:49
  • thanks for reply @Andrew Thompson ... I have fixed the problem...in that code I didn't use setSize(X,Y) method ...that is why i was not getting the view of the table on frame...and also didn't use any layout manager . – user Mar 12 '16 at 18:19
  • 2
    *"I have fixed the problem.."* The 'fix' is to use layouts. Setting the size is simply a kludge to hide a problem on that specific machine. It will likely break on the next one.. – Andrew Thompson Mar 13 '16 at 02:16

0 Answers0