Hallo,
also so schlimm wars noch nie... habe auch auf jtable visual guide von sun geschaut, mir die demo runtergeladen etc. und ich mache verdammt nochmals nicht anderes. Dennoch wird bei mir immer nur eine Zelle selektiert und nicht die komplette Zeile dazu noch in Dunkelblau, WARUM ???
Damit mUSS es funtionieren!!!
kompletter Codeder Tabelle:
also so schlimm wars noch nie... habe auch auf jtable visual guide von sun geschaut, mir die demo runtergeladen etc. und ich mache verdammt nochmals nicht anderes. Dennoch wird bei mir immer nur eine Zelle selektiert und nicht die komplette Zeile dazu noch in Dunkelblau, WARUM ???
Code:
tabelle.setRowSelectionAllowed(true);
//tabelle.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
tabelle.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
Damit mUSS es funtionieren!!!
kompletter Codeder Tabelle:
Code:
public class ImageListePanel extends JPanel implements ActionListener , ListSelectionListener
{
static final long serialVersionUID = 1L;
private SettingsPanel settings;
private JButton loadListBT = new JButton("Liste laden");
private JButton saveListBT = new JButton("Liste speichern");
private JButton addRowBT = new JButton();
private JButton delRowBT = new JButton();
private DefaultListModel listModel = new DefaultListModel();
private JList liste = new JList(listModel);
private JScrollPane listbereich = new JScrollPane(liste);
private String[] spaltennamen = {"Status" , "Gruppe" , "Programm" , "Aufgabe" , "Datenträger" };
private String[][] tabellendaten = new String [700][5];
DefaultTableModel dm;
JTable tabelle;
TrayIcon trayIcon = null;
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("sichtbar machen");
MainWindow myWindow;
public ImageListePanel() throws AWTException
{
setLayout(null);
add(loadListBT);
add(saveListBT);
add(listbereich);
add(addRowBT);
add(delRowBT);
/*if (SystemTray.isSupported())
{
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("refresh.png");
MouseListener mouseListener = new MouseListener() {
public void mouseClicked(MouseEvent e) {
System.out.println("Tray Icon - Mouse clicked!");
}
public void mouseEntered(MouseEvent e) {
System.out.println("Tray Icon - Mouse entered!");
}
public void mouseExited(MouseEvent e) {
System.out.println("Tray Icon - Mouse exited!");
}
public void mousePressed(MouseEvent e) {
System.out.println("Tray Icon - Mouse pressed!");
}
public void mouseReleased(MouseEvent e) {
System.out.println("Tray Icon - Mouse released!");
}
};
popup.add(defaultItem);
ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Exiting...");
System.exit(0);
}
};
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "Tray Demo", popup);
tray.add(trayIcon);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
trayIcon.displayMessage("Action Event",
"An Action Event Has Been Peformed!",
TrayIcon.MessageType.INFO);
}
};
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
trayIcon.addMouseListener(mouseListener);
trayIcon.displayMessage("Finished downloading",
"Your Java application has finished downloading",
TrayIcon.MessageType.INFO);
}
else
{
System.err.println("System tray is currently not supported.");
}*/
listbereich.setBounds(826,0,160,340);
loadListBT.setBounds(826,468,158,60);
saveListBT.setBounds(826,529,158,60);
addRowBT.setBounds(826,341,40,40);
delRowBT.setBounds(867,341,40,40);
loadListBT.setIcon(new ImageIcon("images/pasteurl.png"));
saveListBT.setIcon(new ImageIcon("images/refresh.png"));
addRowBT.setIcon(new ImageIcon("images/add.row.png"));
delRowBT.setIcon(new ImageIcon("images/delete.row.png"));
dm = new DefaultTableModel(tabellendaten,spaltennamen);
tabelle = new JTable( dm ){
/**
*
*/
private static final long serialVersionUID = 1L;
Class[] types = new Class [] {
Boolean.class, String.class, String.class, String.class, String.class
};
@SuppressWarnings("unchecked")
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex)
{
Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
/*---------------------------------------------------------------------------*/
if (rowIndex % 2 == 0 && !isCellSelected(rowIndex,vColIndex))
{
c.setBackground(new Color (245,245,245));
}
else if (rowIndex % 2 == 0)
{
c.setBackground(new Color (245,245,245));
}
else
{
c.setBackground(new Color (255,255,255));
}
/*----------------------------------------------------------------------------*/
return c;
}
};
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
tabelle.getColumnModel().getColumn(1).setCellRenderer(renderer);
tabelle.setRowSelectionAllowed(true);
//tabelle.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
tabelle.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
/* tabelle.addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseMoved(final MouseEvent evt)
{
Point p = evt.getPoint();
int row = tabelle.rowAtPoint(p);
int column = tabelle.columnAtPoint(p);
tabelle.editCellAt(row, column);
}
});*/
/* tabelle.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent evt)
{
;}
});*/
JScrollPane scrollPane = new JScrollPane( tabelle );
add(scrollPane);
scrollPane.setBounds(0,0,826,650);
tabelle.setRowHeight(22);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
tabelle.setAutoCreateRowSorter(true);
listbereich.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
listbereich.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
liste.setCellRenderer(new Renderer());
listModel.addElement("bla bla bla");
addRowBT.addActionListener(this);
delRowBT.addActionListener(this);
liste.addListSelectionListener((ListSelectionListener) this);
setColumnWidth();
}
public void setSP(SettingsPanel object) {
this.settings = object;
}
public void valueChanged( ListSelectionEvent e )
{
if(!e.getValueIsAdjusting())
{
}
}
public void setColumnWidth() {
tabelle.getColumnModel().getColumn(0).setPreferredWidth(40);
tabelle.getColumnModel().getColumn(1).setPreferredWidth(50);
tabelle.getColumnModel().getColumn(2).setPreferredWidth(100);
tabelle.getColumnModel().getColumn(3).setPreferredWidth(500);
tabelle.getColumnModel().getColumn(4).setPreferredWidth(100);
}
public void actionPerformed(final ActionEvent e)
{
if(e.getSource().equals( addRowBT))
{
dm.insertRow(tabelle.getSelectedRow()+1, new Object[]{});
}
if(e.getSource().equals( delRowBT))
{
if(tabelle.getSelectedRow() == -1)
{
}
else
{
dm.removeRow(tabelle.getSelectedRow());
}
}
}
public void mousePressed(MouseEvent e)
{
dm.setValueAt("fff",1,1);
}
}