dcsimg
one scrollpane and 2 tableviews
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   gauravj_reddy
Posted On:   Thursday, January 8, 2009 05:18 PM

I want to use one scrollpane for 2 table views. I have 2 radio buttons , which on selection displays table. The table has different values for every radio button and need to select rows and pass them further. I have each table for every radio button click but want to display in same scroll pane as the table properties remain same but table models are different. I implemented this but when i select the different radio button, the panel becomes empty. the table model has values but the scroll pane is not visible. There is no error message though. Is there any other alternative? Thanks. this is the code - /** * This method initializ   More>>


			
I want to use one scrollpane for 2 table views.

I have 2 radio buttons , which on selection displays table. The table has different values for every radio button and need to select rows and pass them further.
I have each table for every radio button click but want to display in same scroll pane as the table properties remain same but table models are different.

I implemented this but when i select the different radio button, the panel becomes empty. the table model has values but the scroll pane is not visible.
There is no error message though.

Is there any other alternative?
Thanks.


			

this is the code -


/**
* This method initializes this
*
* @return void
*/
private void initialize() {
java.awt.GridBagConstraints gridBagConstraints;

scrollPane = new javax.swing.JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

table = new javax.swing.JTable();
buttonPanel = new javax.swing.JPanel();
listNameLabel = new javax.swing.JLabel();
listDescriptionLabel = new javax.swing.JLabel();

titleLabel = new javax.swing.JLabel();


buttonPanel = new javax.swing.JPanel();
transferButton = new javax.swing.JButton();
resetButton = new javax.swing.JButton();

legListsRadioButton = new javax.swing.JRadioButton();
generalListsRadioButton = new javax.swing.JRadioButton();

legListsRadioButton = new JRadioButton("Legislative", false);
generalListsRadioButton = new JRadioButton("General", true);//default



setLayout(new java.awt.GridBagLayout());


tableGen = new JTable();
tableGen.setAutoCreateColumnsFromModel(true);
tableGen.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
tableGen.setDefaultRenderer(String.class, new TableCellRenderer());

tableLeg = new JTable();
tableLeg.setAutoCreateColumnsFromModel(true);
tableLeg.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
tableLeg.setDefaultRenderer(String.class, new TableCellRenderer());



legListsRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (legListsRadioButton.isSelected())
{
listType = "L";

setLegListTableModel(listType);//setting tablemodel
tableGen.setEnabled(false);

initializeLegList();
}
}

});


generalListsRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (generalListsRadioButton.isSelected())
{
listType = "G";

setGenListTableModel(listType);//setting tablemodel

tableLeg.setEnabled(false);
initializeGenList();

}
}
});
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(legListsRadioButton);
buttonGroup.add(generalListsRadioButton);
Box orderBox = new Box(BoxLayout.X_AXIS);
orderBox.setBorder(BorderFactory.createTitledBorder("Type of Lists"));
orderBox.add(legListsRadioButton);
orderBox.add(generalListsRadioButton);
orderBox.add(Box.createVerticalStrut(2));


gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
add(orderBox, gridBagConstraints);


if (!legListsRadioButton.isSelected())
{
listType = "G";

setGenListTableModel(listType); //call separate method for setting table model for diff listType

initializeGenList();

}
if (legListsRadioButton.isSelected())
{
listType = "L";

setLegListTableModel(listType); //call separate method for setting table model for diff listType
tableGen.setEnabled(false);
initializeLegList();

}


}

private void initializeLegList() {
java.awt.GridBagConstraints gridBagConstraints;


JScrollPane scrollPane = new JScrollPane(
tableLeg, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

scrollPane.setViewportView(tableLeg);

gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
this.add(scrollPane, gridBagConstraints);

}

private void initializeGenList() {
java.awt.GridBagConstraints gridBagConstraints;

JScrollPane scrollPane = new JScrollPane(
tableGen, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

scrollPane.setViewportView(tableGen);


gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
this.add(scrollPane, gridBagConstraints);


}



   <<Less
About | Sitemap | Contact