Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Table size is coming as a full size of a frame when i used gridlayout, please Help me

 
Karan Das
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFrame newFrame= new JFrame();

newFrame.setLayout(new GridLayout(7, 1));
String[] pId = {"2008-10-05", "2009-10-09", "2009-01-01"};
prptCombo = new JComboBox(pId);
pIdlabel = new JLabel("PrppertyId");
ownerLabel = new JLabel("Owner Details");
ownerTextArea = new JTextArea();
ownerTextArea.setColumns(20);
ownerTextArea.setRows(5);
JPanel newPanel1 = new JPanel();
JPanel newPanel2 = new JPanel();
JPanel newPanel3 = new JPanel();
JPanel newPanel4 = new JPanel();
JPanel newPanel5 = new JPanel();
JPanel newPanel6 = new JPanel();
JPanel newPanel7 = new JPanel();
taxLabel = new JLabel("Tax");


//Adding table area
JTable jTable1 = new JTable();

String[] columnNames = {"2000-01",
"2001-02",
"2002-03",
"2003-04",
"2004-05",
"2005-06",
"2006-07",
"2007-08",
"2008-09",
"2009-10"};

Object[][] data = {
{null, null,
null, null, null, null, null, null, null, null}
};



final JTable table = new JTable(data, columnNames);

table.setPreferredScrollableViewportSize(new Dimension(500, 500));
table.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(table);
JScrollPane scrollPane1 = new JScrollPane(ownerTextArea);

//Adding values are panel
newPanel1.add(pIdlabel);
newPanel1.add(prptCombo);
newPanel2.add(ownerLabel);
newPanel2.add(scrollPane1);
//newPanel5.add(taxLabel);


newPanel3.setLayout(new GridLayout(2,1));
scrollPane.setPreferredSize(new Dimension(200, 100));
newPanel3.add(taxLabel);
newPanel3.add(scrollPane);


JFrame frame2=new JFrame();
//adding panels to the frame
newFrame.add(newPanel4);
newFrame.add(newPanel1);
newFrame.add(newPanel2);
// newFrame.add(newPanel7);
// newFrame.add(newPanel5);
newFrame.add(newPanel3);
newFrame.add(newPanel6);

 
Lou Caudell
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't notice it in your code here, but it sounds as if you are setting the gbc fill to expand to available space.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use GridLayout here as it's not a good fit. There are many other layouts available, and I suggest that you practice using them all if you want to make your apps look better. For instance:

 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karan, next time please Use Code Tags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic