Results 1 to 8 of 8

Thread: JScrollPanel

  1. #1
    razmyasdfg is offline Member
    Join Date
    Jul 2008
    Location
    London (Kingsbury)
    Posts
    41
    Rep Power
    0

    Default JScrollPanel

    i have scrollpabel with a JTabel the Jtable has 2 columns (Barcode & Item_Name) i have add the scrollpanel to JFrame. everything work well. but when i close the JFrame and open it again the JTable columns become double i mean there are 4 columns in my table (2 Barcode and 2 Item_Name columns )

    anybody know how to sort this out?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You've got a bug in your code and we'd likely need to see the code to figure out why. I can guess but would rather not.

  3. #3
    razmyasdfg is offline Member
    Join Date
    Jul 2008
    Location
    London (Kingsbury)
    Posts
    41
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    You've got a bug in your code and we'd likely need to see the code to figure out why. I can guess but would rather not.
    Java Code:
    package com.einix.manager_gui_panels;
    
    import java.util.Vector;
    
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.SpringLayout;
    
    public class Edit_Float extends JPanel {
    	//labels
    	private static JLabel Float_ID_Label = new JLabel("Float_ID");
    	private static JLabel Float_Amount_Label = new JLabel("Amount");
    	private static JLabel Date_Label = new JLabel("Date");
    	private static JLabel Float_New_Amount_Label = new JLabel("New Amount");
    	
    	//values
    	private static JComboBox Float_ID_Value = new JComboBox();
    	private static JTextField Float_Amount_Value = new JTextField(15);//old amount
    	private static JTextField Date_Value = new JTextField(15);
    	private static JTextField Float_New_Amount_Value = new JTextField(15);
    	
    	private static JButton Confirm_Button = new JButton("Confirm");
    	private static JButton Cancel_button = new JButton("Cancel");
    	
    	//layout
    	private static SpringLayout layout = new SpringLayout();
    	//JTabel and other variables
    	private static JTable Float_Tabel;
    	private static JScrollPane scrollpanel;
    	private static Vector Column_Name = new Vector();
    	private static Vector Row_Data = new Vector();
    	
    	public Edit_Float(){
    		setLayout(layout);
    		//labels
    		add(Float_ID_Label);
    		layout.putConstraint(SpringLayout.WEST, Float_ID_Label, 50, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_ID_Label, 50, SpringLayout.NORTH, this);
    		
    		add(Float_Amount_Label);
    		layout.putConstraint(SpringLayout.WEST, Float_Amount_Label, 50, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_Amount_Label, 85, SpringLayout.NORTH, this);
    		
    		add(Date_Label);
    		layout.putConstraint(SpringLayout.WEST, Date_Label, 50, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Date_Label, 120, SpringLayout.NORTH, this);
    		
    		add(Float_New_Amount_Label);
    		layout.putConstraint(SpringLayout.WEST, Float_New_Amount_Label, 50, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_New_Amount_Label, 155, SpringLayout.NORTH, this);
    		
    		//values
    		add(Float_ID_Value);
    		layout.putConstraint(SpringLayout.WEST, Float_ID_Value, 200, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_ID_Value, 50, SpringLayout.NORTH, this);
    		
    		add(Float_Amount_Value);
    		layout.putConstraint(SpringLayout.WEST, Float_Amount_Value, 200, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_Amount_Value, 85, SpringLayout.NORTH, this);
    		
    		add(Date_Value);
    		layout.putConstraint(SpringLayout.WEST, Date_Value, 200, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Date_Value, 120, SpringLayout.NORTH, this);
    		
    		add(Float_New_Amount_Value);
    		layout.putConstraint(SpringLayout.WEST, Float_New_Amount_Value, 200, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_New_Amount_Value, 155, SpringLayout.NORTH, this);
    		
    		add(Confirm_Button);
    		layout.putConstraint(SpringLayout.WEST, Confirm_Button, 150, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Confirm_Button, 200, SpringLayout.NORTH, this);
    		
    		add(Cancel_button);
    		layout.putConstraint(SpringLayout.WEST, Cancel_button, 250, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Cancel_button, 200, SpringLayout.NORTH, this);
    		
    		//Placing JTable
    		Column_Name.addElement("Float_ID");
    		Column_Name.addElement("Amount");
    		
    		Float_Tabel = new JTable(Row_Data, Column_Name);
    		scrollpanel = new JScrollPane(Float_Tabel);
    		
    		add(scrollpanel);
    		layout.putConstraint(SpringLayout.WEST, scrollpanel, 50, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,scrollpanel, 250, SpringLayout.NORTH, this);
    	}
    
    }
    Java Code:
    public class Float_GUI extends JFrame {
    	private static JTabbedPane TabbedPane;
    	private static Float Float;
    	private static Edit_Float Edit_Float;
    	public Float_GUI(){
    		
    	super("Float");
    	Dimension screen = 	Toolkit.getDefaultToolkit().getScreenSize();
    	setSize(screen.width, screen.height);
    	//setDefaultCloseOperation(JFrame.NORMAL);
    	TabbedPane = new JTabbedPane();
    	Float = new Float();
    	Edit_Float = new Edit_Float();
    	
    	TabbedPane.addTab("New Float", Float);
    	TabbedPane.addTab("Edit Float", Edit_Float);
    	
    	add(TabbedPane);
    	setVisible(true);
    	
    	}
    }

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Hm, I'm still at a loss to explain as the code above doesn't compile (it's missing the Float class for one), and also it doesn't demonstrate your problem for us that I can see.

  5. #5
    razmyasdfg is offline Member
    Join Date
    Jul 2008
    Location
    London (Kingsbury)
    Posts
    41
    Rep Power
    0

    Default

    here is the Float Calss

    Java Code:
    package com.einix.manager_gui_panels;
    
    import java.sql.ResultSet;
    
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SpringLayout;
    
    import com.einix.pos.system.v1.Current_Time;
    import com.einix.pos.system.v1.Database_Loder;
    import com.einix.pos.system.v1.Database_Loder_Parameter;
    
    public class Float extends JPanel {
    	//class variables;
    	private static int Float_ID;
    	private static Employee Employee;
    	private static int Employee_ID;
    	private static Current_Time Current_Time;
    	private static Double Float_Amount;
    	
    	//Database Functions
    	private static Database_Loder database_loader;
    	private static Database_Loder_Parameter database_loader_parameter;
    	private static ResultSet resultset;
    	//labels
    	private static JLabel Float_ID_Label = new JLabel("Float_ID");
    	private static JLabel Date_Label = new JLabel("Date");
    	private static JLabel Float_Amount_Label = new JLabel("Amount");
    	
    	//values
    	private static JTextField Float_ID_Value = new JTextField(15);
    	private static JTextField Date_Value = new JTextField(15);
    	private static JTextField Float_Amount_Value = new JTextField(15);
    	
    	private static JButton Add_Button = new JButton("Add");
    	private static JButton Cancel_Button = new JButton("Cancel");
    	
    	//layout
    	private static SpringLayout layout = new SpringLayout();
    	//constructor
    	public Float(){
    		setLayout(layout);
    		//adding labels
    		add(Float_ID_Label);
    		layout.putConstraint(SpringLayout.WEST, Float_ID_Label, 50, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_ID_Label, 50, SpringLayout.NORTH, this);
    		
    		add(Date_Label);
    		layout.putConstraint(SpringLayout.WEST, Date_Label, 50, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Date_Label, 85, SpringLayout.NORTH, this);
    		
    		add(Float_Amount_Label);
    		layout.putConstraint(SpringLayout.WEST, Float_Amount_Label, 50, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_Amount_Label, 120, SpringLayout.NORTH, this);
    		//adding values
    		
    		add(Float_ID_Value);
    		layout.putConstraint(SpringLayout.WEST, Float_ID_Value, 200, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_ID_Value, 50, SpringLayout.NORTH, this);
    		
    		add(Date_Value);
    		layout.putConstraint(SpringLayout.WEST, Date_Value, 200, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Date_Value, 85, SpringLayout.NORTH, this);
    		
    		add(Float_Amount_Value);
    		layout.putConstraint(SpringLayout.WEST, Float_Amount_Value, 200, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Float_Amount_Value, 120, SpringLayout.NORTH, this);
    		
    		add(Add_Button);
    		layout.putConstraint(SpringLayout.WEST, Add_Button, 200, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Add_Button, 180, SpringLayout.NORTH, this);
    		
    		add(Cancel_Button);
    		layout.putConstraint(SpringLayout.WEST, Cancel_Button, 280, SpringLayout.WEST, this);
    		layout.putConstraint(SpringLayout.NORTH,Cancel_Button, 180, SpringLayout.NORTH, this);
    	}
    	public static int getFloat_ID() {
    		return Float_ID;
    	}
    
    	public static void setFloat_ID(int float_ID) {
    		Float_ID = float_ID;
    	}
    
    	public static Employee getEmployee() {
    		return Employee;
    	}
    
    	public static void setEmployee(Employee employee) {
    		Employee = employee;
    	}
    
    	public static Current_Time getCurrent_Time() {
    		return Current_Time;
    	}
    
    	public static void setCurrent_Time(Current_Time current_Time) {
    		Current_Time = current_Time;
    	}
    
    	public static Double getFloat_Amount() {
    		return Float_Amount;
    	}
    
    	public static void setFloat_Amount(Double float_Abount) {
    		Float_Amount = float_Abount;
    	}
    	
    	public int getEmployee_ID(){
    		return this.Employee.getEmployee_ID();
    	}
    
    }

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I take that back, I think I see your problem: misuse of static modifier. You should not use static methods or variables unless you have VERY good reason for doing so. In this case none of these variables should be static:

    Java Code:
       private static JLabel Float_ID_Label = new JLabel("Float_ID");
       private static JLabel Float_Amount_Label = new JLabel("Amount");
       private static JLabel Date_Label = new JLabel("Date");
       private static JLabel Float_New_Amount_Label = new JLabel("New Amount");
    
       // values
       private static JComboBox Float_ID_Value = new JComboBox();
       private static JTextField Float_Amount_Value = new JTextField(15);// old
       // amount
       private static JTextField Date_Value = new JTextField(15);
       private static JTextField Float_New_Amount_Value = new JTextField(15);
    
       private static JButton Confirm_Button = new JButton("Confirm");
       private static JButton Cancel_button = new JButton("Cancel");
    
       // layout
       private static SpringLayout layout = new SpringLayout();
       // JTabel and other variables
       private static JTable Float_Tabel;
       private static JScrollPane scrollpanel;
       private static Vector Column_Name = new Vector();
       private static Vector Row_Data = new Vector();
    If you're doing this because the compiler is complaining that you shouldn't use non-static variables in a static way, then you're fixing the error backwards. So again, make all of these instance variables, and I think that this might fix your problem.

  7. #7
    razmyasdfg is offline Member
    Join Date
    Jul 2008
    Location
    London (Kingsbury)
    Posts
    41
    Rep Power
    0

    Default

    thank you sooooooo much m8. that did work well thank you

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You're quite welcome and a good lesson: use static sparingly and only for well-defined reasons.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •