-1

Dear Friends,

I have a frame which is a JSplitPane which is split horizontally into two. On the upper half I want a JFrame to appear and on the lower half I want a JTable to appear. I tired but couldn't get the answer correctly. Will anyone be able to help me out.

Regards

Sincerelibran

4
Contributors
5
Replies
8
Views
6 Years
Discussion Span
Last Post by jouj
0

You can't have a Frame within a Frame. You can have a JInternalFrame within a JFrame, but not another JFrame. Why do want a JFrame inside of a JFrame? If it's because you want to reuse a class that currently extends JFrame, then, well, now you see one of the problems with extending top-level window classes. Rewrite it to extend JPanel (and it's main method can still create a JFrame to put itself inside of so it can still be used stand-alone, which is how it should be done).

0

Dear Friends,

I'm using the following code. The table that appears doesn't cover the entire area of the second half of the screen. It comes on one side (left side). I want it to cover the entire area. Kindly help me out in this. I'm posting both the programs that I use.
LibraryMainMenu.java

// Main Menu
import java.awt.*;
import java.sql.*;
import javax.swing.*;

public class LibraryMainMenu{

	static JPanel createPanel(String[] sa) {

		JPanel p = new JPanel(new GridLayout(0,1));

		for(int i=0;i<sa.length;++i) p.add(new JLabel(sa[i]));
      		return p;
   	}

	public static void main(String[] args) {

		
		JPanel p1 = createPanel(new String[]{
         		"James Dean","Johnny Depp","Scarlett Johansson",
         		"Keira Knightley","Robert Carlyle","Ewan McGregor",
         		"Sean Connery","Leonardo di Caprio"}
      		);
		p1.setMinimumSize(new Dimension(1151,380));

      		JPanel p2 = new JPanel();
		TableTest tt = new TableTest();
		p2.setLayout(new BorderLayout());
		p2.add(tt, BorderLayout.LINE_START);
		p2.setBackground(new Color(0,120,120));
		
      		final JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, p1, p2);
      		jSplitPane.setContinuousLayout(true);

      		JFrame f = new JFrame("SABS - Library Management System");
      		f.getContentPane().add(jSplitPane);
      		f.setSize(1151, 860);
      		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      		f.setVisible(true);
   	}

}

TableTest.java

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.BorderLayout;

public class TableTest extends JPanel{

	
	DefaultTableModel dtm;
	JTableHeader header;
	JScrollPane pane;
	JTable t;
	JPanel panel;

	public TableTest(){


			panel = new JPanel();
			panel.setLayout(new BorderLayout());
			dtm = new DefaultTableModel(6,9);
			t = new JTable(dtm);
			t.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

      			dtm.addColumn("Marks");
			dtm.addColumn("Gender");

      			//add column at third position
	      		positionColumn(t,0);
      			positionColumn(t,1);

			header = t.getTableHeader();
			//t.setLocation(5,5);
      			header.setBackground(new Color(0,75,200));
      			header.setForeground(new Color(255,255,255));
			pane = new JScrollPane(t);
			panel.add(pane, BorderLayout.CENTER);
			add(panel);
		setSize(1150,430);
	}
  	public void positionColumn(JTable table,int col_Index) {

        	table.moveColumn(table.getColumnCount()-1, col_Index);
  	}
}
0

just add setPreferredSize to your scrollPane

pane.setPreferredSize(new Dimension(1100,420));
0

hello guys i'm new to java programming . i want to know if i can create a table not necessary SQL tabel a simple table .
in a JSplitPane (like innerSplitPane) if any one can help .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.