Program jest w Javie, ale komórce JTable ustawiłem obrazek ze strony i aby rozmiar jego był ustalony zamieściłem go w kodzie html, lecz liczyłem, że w jakiś sposób da się zrobić aby można było widzieć cały obrazek nie rozszerzając wysokości wiersza JTable.
Przykładowy kod:
Kopiuj
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Main {
private JFrame frame;
private JTable table;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main window = new Main();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Main() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(panel, GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
.addContainerGap())
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(panel, GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
.addContainerGap())
);
JScrollPane scrollPane = new JScrollPane();
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
.addContainerGap(88, Short.MAX_VALUE)
.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 316, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap()
.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
.addContainerGap())
);
table = new JTable();
table.setModel(new DefaultTableModel(
new Object[][] {
{1, "Czapka dzianinowa", 40.00, "<html><img class=\"product\" id=\"productimage_1636733\" src=\"http://www.c-and-a.com/iview/FRONT_PRODUCT_OVERVIEW/161049_1.jpg\" width=\"178\" height=\"307\" alt=\"Sklep internetowy C&A | Czapka dzianinowa - kolor: ciemnoniebieski\" title=\"Sklep internetowy C&A | Czapka dzianinowa - kolor: ciemnoniebieski\"></html>"},
{2, null, null, null},
},
new String[] {
"nr", "nazwa", "cena", "obrazek"
}
) {
Class[] columnTypes = new Class[] {
Integer.class, String.class, Double.class, Object.class
};
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
});
table.getColumnModel().getColumn(0).setPreferredWidth(24);
table.getColumnModel().getColumn(1).setPreferredWidth(174);
table.getColumnModel().getColumn(3).setPreferredWidth(206);
scrollPane.setViewportView(table);
panel.setLayout(gl_panel);
frame.getContentPane().setLayout(groupLayout);
}
}