continue..
private JRadioButton createRadioButtons(final int itemsPerPage, final int target, String title) {
JRadioButton radio = new JRadioButton(title);
radio.setForeground(Color.BLUE);
radio.setUI(ui);
radio.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
showPages(itemsPerPage, target);
}
});
return radio;
}
private RowFilter<Model,Integer> filter(final int itemsPerPage, final int target) {
return new RowFilter<Model,Integer>() {
public boolean include(Entry<? extends Model, ? extends Integer> entry) {
int ei = entry.getIdentifier();
return (target*itemsPerPage<=ei && ei<target*itemsPerPage+itemsPerPage);
}
};
}
public static void main(String[] args) {
JFrame frame = new JFrame("Table");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(new GridView());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
class RadioButtonUI extends BasicRadioButtonUI {
public Icon getDefaultIcon() {
return null;
}
private static Dimension size = new Dimension();
private static Rectangle rec1 = new Rectangle();
private static Rectangle rec2 = new Rectangle();
private static Rectangle rec3 = new Rectangle();
public synchronized void paint(Graphics g, JComponent c) {
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
Font f = c.getFont();
g.setFont(f);
FontMetrics fm = c.getFontMetrics(f);
Insets i = c.getInsets();
size = b.getSize(size);
rec1.x = i.left;
rec1.y = i.top;
rec1.width = size.width - (i.right + rec1.x);
rec1.height = size.height - (i.bottom + rec1.y);
rec2.x = rec2.y = rec2.width = rec2.height = 0;
rec3.x = rec3.y = rec3.width = rec3.height = 0;
String text = SwingUtilities.layoutCompoundLabel(
c, fm, b.getText(), null,
b.getVerticalAlignment(), b.getHorizontalAlignment(),
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
rec1, rec2, rec3,
0);
if(c.isOpaque()) {
g.setColor(b.getBackground());
g.fillRect(0,0, size.width, size.height);
}
if(text==null) return;
g.setColor(b.getForeground());
if(!model.isSelected() && !model.isPressed() && !model.isArmed()
&& b.isRolloverEnabled() && model.isRollover()) {
g.drawLine(rec1.x, rec1.y+rec1.height,
rec1.x+rec1.width, rec1.y+rec1.height);
}
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if(v!=null) {
v.paint(g, rec3);
}else{
paintText(g, b, rec3, text);
}
}
}
class Model extends DefaultTableModel {
Model(){
JTable table = new JTable(this);
addColumn("Name");
addColumn("Address");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306/register","root";, "root");
String query = "select * from data";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
String name=rs.getString("name");
String address=rs.getString("address");
addRow(new Object[] { name,address });
}
}
catch(Exception e){}
}
}
Thanks