Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Urgent help needed regarding JTable display

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Urgent help needed regarding JTable display

    hi,

    I am very new to forums and I am very new to swings.I had devloped a JFRame which contains Jtabbedpane.In the first tab of the jtabbedpane i had placed a JTable.my problem is the jtable is displaying well when jframe is not maximized.but when i maximized the frame using maximize button and if i try to scroll the jtable it is not displaying well.i am not understanding why this distrortion is happening.I searched in all forums about this but i didnt get any solution.
    Plz help me about this i am stuggling for past two weeks.Plz ignore mistakes in my english.[LIST]


    Here is my complete code of my class
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    class Testdemo
    		extends 	JFrame
    {
    	private		JTabbedPane tabbedPane;
    	private		JPanel		panel1;
    	private		JPanel		panel2;
    	private		JPanel		panel3;
    JTable mappingTable;
    JScrollPane pane;
     
    	public Testdemo()
    	{
    		// NOTE: to reduce the amount of code in this example, it uses
    		// panels with a NULL layout.  This is NOT suitable for
    		// production code since it may not display correctly for
    		// a look-and-feel.
     
    		setTitle( "Tabbed Pane Application" );
    		setSize( 300, 200 );
    		setBackground( Color.gray );
     
    		JPanel topPanel = new JPanel();
    		topPanel.setLayout( new BorderLayout() );
    		getContentPane().add( topPanel );
     
    		// Create the tab pages
    		createPage1();
    		createPage2();
    		createPage3();
     
    		// Create a tabbed pane
    		tabbedPane = new JTabbedPane();
    		tabbedPane.addTab( "Page 1", panel1 );
    		tabbedPane.addTab( "Page 2", panel2 );
    		tabbedPane.addTab( "Page 3", panel3 );
    		topPanel.add( tabbedPane, BorderLayout.CENTER );
    	}
     
    	public void createPage1()
    	{
    		panel1 = new JPanel();
    		panel1.setLayout( new BorderLayout() );
     
    		Object values[] = { "SNo","Source system", "Source Table","Source field Name","Data Type","Field Length","NaturalIdentifier","Target System","Target Table","Field Name","Data Type","Length","Primary Key","Field Description","Data Mapping Rule","Transformation Rules","ETL Load rules(one per table)","Comment","Status" };
    		 TableModel model = new DefaultTableModel(values, 1010){
    				public boolean isCellEditable(int row,int column)
    					{
     
    					if(column==0||column==5||column==11)
    					return false;
    					return true;
    					}
    				};
    			 mappingTable = new javax.swing.JTable (1010,19) {
    					 public Component prepareRenderer(TableCellRenderer renderer, int row, int column){
    					        Component returnComp = super.prepareRenderer(renderer, row, column);
    					        Color alternateColor = new Color(252,242,206);
    					        Color whiteColor = Color.WHITE;
    					        if (!returnComp.getBackground().equals(getSelectionBackground())){
    					            Color bg = (row % 2 == 0 ? alternateColor : whiteColor);
    					            returnComp .setBackground(bg);
    					            bg = null;
    					        }
    					        return returnComp;
    					 }
     
    					public boolean isCellEditable(int row,int column)
    					{
    						for(int i=0;i<mappingTable.getRowCount();i++)
    						{
    							for(int j=0;j<mappingTable.getColumnCount();j++)
    							{
    								if(mappingTable.getValueAt(i,j)!=null&&mappingTable.getValueAt(i,j).toString().length()>=1)
    								{
    									for(int k=0;k<=i;k++)
    									{
    										mappingTable.setValueAt((k+1), k, 0);
     
    									}
    								}
    							}
    						}
    						if(column==0)
    							return false;
    							return true;
    					}
     
     
    				    };
    				   mappingTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    				   pane = new JScrollPane(mappingTable);
     
    				   JLabel l=new JLabel("KKKKK");
    				   panel1.add(pane,BorderLayout.CENTER);
    	}
     
    	public void createPage2()
    	{
    		panel2 = new JPanel();
    		panel2.setLayout( new BorderLayout() );
     
    		panel2.add( new JButton( "North" ), BorderLayout.NORTH );
    		panel2.add( new JButton( "South" ), BorderLayout.SOUTH );
    		panel2.add( new JButton( "East" ), BorderLayout.EAST );
    		panel2.add( new JButton( "West" ), BorderLayout.WEST );
    		panel2.add( new JButton( "Center" ), BorderLayout.CENTER );
    	}
     
    	public void createPage3()
    	{
    		panel3 = new JPanel();
    		panel3.setLayout( new GridLayout( 3, 2 ) );
     
    		panel3.add( new JLabel( "Field 1:" ) );
    		panel3.add( new TextArea() );
    		panel3.add( new JLabel( "Field 2:" ) );
    		panel3.add( new TextArea() );
    		panel3.add( new JLabel( "Field 3:" ) );
    		panel3.add( new TextArea() );
    	}
     
        // Main method to get things started
    	public static void main( String args[] )
    	{
    		// Create an instance of the test application
    		Testdemo mainFrame	= new Testdemo();
    		mainFrame.setVisible( true );
    	}
    }
    Last edited by copeg; July 7th, 2010 at 08:36 AM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Urgent help needed regarding JTable display

    define "not displaying well."

    Can you leave a picture of it "not displaying well" so I have an idea of what is actually happening.

    Regardless, my initial suspect will be the layout. I also suspect mappingTable.setAutoResizeMode(JTable.AUTO_RESIZE_ ALL_COLUMNS); to be a possible issue. If the problem is with BorderLayout, then I'm not going to be much help because I dont use any of Java's stupid provided layouts.

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Urgent help needed regarding JTable display

    hi aussiemcgr,thanks for the reply.

    "not displaying well" means after maximize the frame by clicking on maximize button of the frame,If i scroll the jtable the data in table is jumping from one cell to another cell and some data is missing and it has to display alternate white rows but it is showing zigzagly like continuous color rows or continuous white lines.I am not getting any problem until i maximized the window.

    I had tested the code by removing the line

    mappingTable.setAutoResizeMode(JTable.AUTO_RESIZE_ ALL_COLUMNS);

    still i am getting the same problem.

    for clarification see the sample pics i had attached in pics.zip.first.jpg is before maximized.
    second.jpg is after maximized(observe it some data missed and rows dont hav alternate color).
    Attached Files Attached Files

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Urgent help needed regarding JTable display

    Seems to work OK for me. JRE 1.6.0_20

  5. #5
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Urgent help needed regarding JTable display

    hi Norm,

    R u sure?.Is it working fine in JRE 1.6.0_20?.Did u checked it by maximizing the Jframe and scroll the jtable up and down.You didnt get any distrortion like what i shown in second.jpeg.

    I am using jre1.5.0_06.If it is working is fine in JRE 1.6.0_20,Why it is not working for me?.what may be the problem?.

    Kasi

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Urgent help needed regarding JTable display

    I didn't find any problems. I maximized, scrolled up and down, change pages with the tabs, entered data into the table and it still looked fine.

Similar Threads

  1. Urgent help needed
    By mohit1007 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 23rd, 2010, 09:34 PM
  2. Multi Dimensional Array help NEEDED URGENT
    By bonjovi4u in forum Loops & Control Statements
    Replies: 5
    Last Post: February 13th, 2010, 12:44 AM
  3. display time
    By kalees in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: January 1st, 2010, 07:40 AM
  4. Urgent Help needed with java codes
    By makarov in forum Java Theory & Questions
    Replies: 0
    Last Post: November 13th, 2009, 07:23 AM
  5. Urgent code needed
    By subhvi in forum AWT / Java Swing
    Replies: 4
    Last Post: August 27th, 2009, 12:55 AM