raja syamala

Greenhorn
+ Follow
since Aug 15, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by raja syamala

Hi,
I have a class that extends JFrame and JPanel, JTabbedPane, JButtons etc.. are added to it. I am using
classname.setSize(500,500).
But when I maximize the window manually or resize the window the size of the contents in the frame are changing. Is there a way to set the size of the frame and its components to be constant all the time. I tried to use the same method on the components as well. But the problem still persists.
Tried using pack(). But didn't work the way I want it.
Please let me know if there is any way to set the fixed size.
Thanks in advance.
22 years ago
Hi,
I have a class which extends the frame and has "JTabbedPane" and "JTable" added to it. Look at the following code:
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
JTabbedPane jtp = new JTabbedPane();
jtp.addTab("Songs", new SongsPanel());
contentPane.add(jtp, BorderLayout.NORTH);

DefaultTableModel dtm = new DefaultTableModel();
table = new JTable();
table.setModel(dtm);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
pack();
In the JTabbedPane I have two buttons. When I click on one button it has to show the "JTable". But it is not showing. The action is performing only when I resize the window manually. And if I resize it manually some how my BorderLayout is changing to FlowLayout. Here is the code for the JTabbedPane
JTable table = new JTable();

public SongsPanel() {
super();
JButton b1 = new JButton("View Songs");
b1.setActionCommand("view");
b1.addActionListener(this);
JButton b2 = new JButton("All Songs");
b2.setActionCommand("all");
b2.addActionListener(this);
add(b1);
add(b2);
}

public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("view")) {
DefaultTableModel d1 = (DefaultTableModel) table.getModel();
for(int i=0;i<d1.getRowCount();i++) {>
d1.removeRow(i);
}
final String[] colLabel = {"Name", "Artist"};
final String[][] data = {
{"Come on", "Madonna"},
{"Quit Playing games", "Back Street Boys"}
};
DefaultTableModel dataModel = new DefaultTableModel(data, colLabel);
table.setModel(dataModel);
table.setShowGrid(false);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table, v, h);
add(jsp, BorderLayout.CENTER);
} else if(e.getActionCommand().equals("all")) {
DefaultTableModel d1 = (DefaultTableModel) table.getModel();
for(int i=0;i<d1.getRowCount();i++) {>
d1.removeRow(i);
}
System.out.println(e.getActionCommand());
final String[] colLabel = {"Name", "Artist"};
final String[][] data = {
{"Come on ALL", "ALL Madonna"},
{"ALL Quit Playing games", "ALL Back Street Boys"}
};
DefaultTableModel dataModel = new DefaultTableModel(data,colLabel);
table.setModel(dataModel);
table.setShowGrid(false);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table, v, h);
add(jsp, BorderLayout.CENTER);
}
table.revalidate();
table.repaint();
}
}
Please let me know if I am making any mistakes. I am new to swing API and any suggestions regarding the use of swing components are welcome.
Thanks in advance.
22 years ago