• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem With validate()  RSS feed

 
nabi bux
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Every One I working in Java swing there is Program in which i Defined two containg one is Jpanel for Button one JScroll pane for table
I have there table in data base i want when i click first button the first table appeare when i click secong button secong table apperar bey default when run my code first table appear niccely but when i second table it appeared but half the first table also remain the reaming how can i that first table removed and second table appeard at Jscroll Pane please Help
I try to use validate() repaint () fuction but they doed not work well please
/**
public class DataBase extends JFrame implements ActionListener {/*getContentPane().setLayout(
new BoxLayout( getContentPane(), BoxLayout.Y_AXIS );
. . . . .*/

JButton openButton, macButton, javaButton, motifButton, winButton;
AccessJDBCTest test; // User Definded
JLayeredPane desktop;
JScrollPane jsp;
JTabletable;
JPanel p;
JInternalFrame internalFrame;

public DataBase() {
super("Internal Frame Demo");
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception ex1) {
System.err.println("Unsupported LookAndFeel: " );
}

test =new AccessJDBCTest();

try{
table =test.printTable();

} catch(Exception e){
System.out.println(e);
}

table.setRowHeight(20);
table.setCellSelectionEnabled(true);

// Add the table to a scrolling pane
jsp = new JScrollPane( table );



openButton = new JButton("Open");
macButton = new JButton("Mac");
javaButton = new JButton("Metal");
motifButton = new JButton("Motif");
winButton = new JButton("Windows");
setSize(500, 400);

p = new JPanel(new BorderLayout());
Box left=Box.createVerticalBox();
p.setBorder( new TitledBorder( new EtchedBorder(),"Function Buttton"));
Dimension size=new Dimension(100,20);
p.setBackground(Color.BLACK);

left.add(openButton);
left.add(macButton);
left.add(javaButton);
left.add(motifButton);
left.add(winButton);

openButton.setMaximumSize(winButton.getPreferredSize());
// b2.setMaximumSize(b3.getPreferredSize());
openButton.setMaximumSize(winButton.getPreferredSize());
macButton.setMaximumSize(winButton.getPreferredSize());// Setting he size of Button With respect to Larger Button
javaButton.setMaximumSize(winButton.getPreferredSize());
motifButton.setMaximumSize(winButton.getPreferredSize());


openButton.addActionListener( this );


p.add(left,BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});


this.getContentPane().setBackground(Color.gray);
this.getContentPane().add(jsp,BorderLayout.CENTER);
this.getContentPane().add(p, BorderLayout.WEST);


}
public void actionPerformed( ActionEvent e )
{
if(e.getActionCommand()=="Open");

{
//JavaFileView jfv=new JavaFileView();
try{
table =test.printTableName();

} catch(Exception el){
System.out.println(el);
}
jsp.removeAll();
jsp=new JScrollPane(table);
jsp.revalidate();

this.getContentPane().add(jsp,BorderLayout.CENTER);
this.getContentPane()vlidate();


}
}

public static void main(String args[]) {
DataBase sif = new DataBase();
sif.setVisible(true);
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!