JComboBox in the JTable Header - TableCellEditor problem
Hi,
I have added JComboBox into the JTableHeader. But I can't Edit that combobox. It is looking like an icon. I have added JPanel into the JTable Header Row. In JPanel i have added one JLable and JComboBox.
Please any one of you give me the solution.
Thanks,
Shrini V.
The table will display what ever value it has in its model. When you add the row, there is no data in the second column. You'll have to supply it.
public void insertMyRowCombo (Object [] r,
JComboBox c,
JTable t) {
// {"rut", "puntaje cas", "beneficio", "fecha inicio", "fecha termino", "monto"};
DefaultTableModel tm = (DefaultTableModel) t.getModel();
tm.addRow(r);
TableColumn col = t.getColumnModel().getColumn(2);
col.setCellEditor(new DefaultCellEditor(c));
tm.setValueAt( c.getItemAt(0), 0, 2); //manually supply the value to col 2
}ICE
Similar Messages
-
Not able to edit the JTextField under the JTable header
Hi,
As per my requirement, i need to add the text field in JTable header for filtering the table records.
i have added the text field but not able to enter any value (it is disabled).
Can anyone please help me on this?Welcome to the forum.
After reading how to format Code in this forum (SQL and PL/SQL FAQ ),
please show us the code of your TableHeader implementation.
bye
TPD -
Focus for JCombobox in the JTable
Hi GentleMen,
I have one combobox in the JTable and when i change the item
in the combobox two messages poped up and item is set to
the same previous item.Here my problem is that when i get to the
first item the focus not being on the same ombobox . What might be the
problem. Help me with the example code.
Thanks & Regards,
PothanumaraNo idea what you are asking.
Here is an example that uses a different combo box for each row:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting. -
How can i adjest the width of the JTable Header
hi all,
I have putted group header in JTable, due to this the width of the JTable and width of the column of the row is little bit variation. pleases suggest me any way to avoid it.
Thanks
Dayananda B VTableColumn tCol = null;
for(int i = 0; i <= 5; i++){
tCol = tblData.getColumnModel().getColumn(i);
if(i == 1)
tCol.setPreferredWidth(130);
else
tCol.setPreferredWidth(30);
} -
i created a small JFrame to test removing the JTable header
the Sutation : a JTable in JScrollPane in JPannel.
the Test as well as my program.
i create Model in both cases. my won.
the properties of the both components are almost the same.
the diffrence : in the test JFrame look great.
in my program it remains a small hieght from the Header about 2pixels. and i can see it.
any help?
thxi created a small JFrame to test removing the JTable
header
the Sutation : a JTable in JScrollPane in JPannel.I can follow you up to this point
the Test as well as my program.? the test of what? and what did they do? you forgot a verb ...
i create Model in both cases. my won.two cases ... which are they? and which is your case that won?
the properties of the both components are almost the
same.oh, two components ... and which are they?
>
the diffrence : in the test JFrame look great.which test?
in my program it remains a small hieght from thewhere is the difference between a test of your program and your program?
Header about 2pixels. and i can see it.
any help?sorry, please explain clearly what your problem is.
thxRommie. -
How to make JTable Header to Blink?
Hi Everybody...
I need the code to blink the JTable Header in Java Swings..
Im trying since long time...
Please help me out...
Thanks in Advance...I have posted it by mistakly...yeh, just like you mistakly cross-posted your other thread/s at javaranch.
i think u dont think positivly..Oh I positivly know you're a fcukwit
better for you to toodle off and try to write a Hello World app. -
How to remove JTable header from JScrollPane?
Hi!
Does anyone know how to remove the JTable header from the JScrollPane the table is placed in? I tried calling
scrollpane.setColumnHeader( null ) and
scrollpane.setColumnHeaderView( null )
but none of the above worked...
Thanks!
FilHi,
The easiest way to do this is to put an extra layer between the table and the scrollpane as follows:-
JPanel p = new JPanel(new BorderLayout());
// Add it to the north rather than center so that the table background color
// won't cover the empty part of the view port.
p.add(table, BorderLayout.NORTH);
JViewport v = tableScroll.getViewport();
v.setView(p);
where table is your JTable and tableScroll is your JScrollPane.
Hope this helps,
Ian -
Hi all,
I have a problem with printing JTable.
My application has a submit button,JTable and Print Button.
As I click on the Submit button, the data is retrieved from the Database(MS Access) and displayed on the JTable.
Now when I click on the Print button, the printer properties dialog box is displayed. But when I click on the print button in the dialog box, nothing is printed on the paper.
I checked the printers and faxes in the control panel, It showed Java printing under the Document name and Printing under the Status. It is displayed for sometime and then disappeared after some time. But nothing is printed on the paper(not even the blank paper).
I tried a lot but couldn't understand the problem.
I have used the following files:
PrintJTable.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.awt.geom.*;
import java.awt.Dimension;
import java.applet.*;
import java.sql.*;
import java.util.*;
import java.net.*;
import java.lang.*;
import javax.swing.table.*;
import javax.swing.event.*;
import javax.swing.border.*;
class PrintJTable implements ActionListener,Printable
Connection connect;
ResultSet rs;
JTable table;
JScrollPane tableAggregate;
DisplayTable displayTable;
JButton print,submitButton;
public PrintJTable()
JFrame frame = new JFrame("Table");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
connect();
displayTable= new DisplayTable();
JButton submitButton= new JButton("SUBMIT");
submitButton.addActionListener(this);
JButton printButton= new JButton("PRINT!");
// for faster printing turn double buffering off
RepaintManager.currentManager( frame).setDoubleBufferingEnabled(false);
printButton.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent evt) {
PrinterJob pj=PrinterJob.getPrinterJob();
pj.setPrintable(PrintJTable.this);
pj.printDialog();
try{
pj.print();
}catch (Exception PrintException) {}
tableAggregate = createTable();
tableAggregate.setBorder(new BevelBorder(BevelBorder.LOWERED));
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(submitButton,BorderLayout.NORTH);
frame.getContentPane().add(tableAggregate,BorderLayout.CENTER);
frame.getContentPane().add(printButton,BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
} // end of constructor
public void connect()
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Opening db connection");
connect = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/db1.mdb","","");
catch (ClassNotFoundException ex) {
System.err.println("Cannot find the database driver classes.");
System.err.println(ex);
catch (SQLException ex) {
System.err.println("Cannot connect to this database.");
System.err.println(ex);
public JScrollPane createTable() {
displayTable= new DisplayTable();
JTable table = new JTable(displayTable);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getTableHeader().setReorderingAllowed(false);
JScrollPane scrollpane = new JScrollPane(table,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
return scrollpane;
} // end of createTable()
public void actionPerformed(ActionEvent ie)
try
Statement statement6=connect.createStatement();
ResultSet rs6=statement6.executeQuery("select * from benf_details");
displayTable.executeQuery(rs6);
statement6.close();
catch(SQLException sqle)
JOptionPane.showMessageDialog(null,"error2"+sqle);
}// end of actionPerformed
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.black);
int fontHeight=g2.getFontMetrics().getHeight();
int fontDesent=g2.getFontMetrics().getDescent();
double pageHeight = pageFormat.getImageableHeight()-fontHeight; //leave room for page number
double pageWidth = pageFormat.getImageableWidth();
System.out.println("page width = " + pageWidth );
double tableWidth = (double) table.getColumnModel().getTotalColumnWidth();
System.out.println("table width = " + tableWidth );
double scale = 1;
if (tableWidth >= pageWidth) {
scale = pageWidth / tableWidth;
System.out.println("scale = " + scale );
double headerHeightOnPage = table.getTableHeader().getHeight() * scale;
double tableWidthOnPage = tableWidth * scale;
double oneRowHeight = (table.getRowHeight() + table.getRowMargin()) * scale;
int numRowsOnAPage = (int)((pageHeight - headerHeightOnPage) / oneRowHeight);
double pageHeightForTable = oneRowHeight * numRowsOnAPage;
int totalNumPages = (int)Math.ceil(((double)table.getRowCount())/numRowsOnAPage);
if(pageIndex >= totalNumPages) {
return NO_SUCH_PAGE;
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
g2.drawString("Page: "+ (pageIndex + 1),(int)pageWidth / 2 - 35,
(int)( pageHeight + fontHeight - fontDesent ));//bottom center
g2.translate( 0f, headerHeightOnPage );
g2.translate( 0f, -pageIndex * pageHeightForTable );
//If this piece of the table is smaller than the size available,
//clip to the appropriate bounds.
if (pageIndex + 1 == totalNumPages) {
int lastRowPrinted = numRowsOnAPage * pageIndex;
int numRowsLeft = table.getRowCount() - lastRowPrinted;
g2.setClip(0, (int)(pageHeightForTable * pageIndex),
(int) Math.ceil(tableWidthOnPage),
(int) Math.ceil(oneRowHeight * numRowsLeft));
//else clip to the entire area available.
else{
g2.setClip(0, (int)(pageHeightForTable * pageIndex),
(int) Math.ceil(tableWidthOnPage),
(int) Math.ceil(pageHeightForTable));
g2.scale(scale,scale);
table.paint(g2);
g2.scale(1/scale,1/scale);
g2.translate( 0f, pageIndex * pageHeightForTable);
g2.translate( 0f, -headerHeightOnPage);
g2.setClip(0, 0,(int) Math.ceil(tableWidthOnPage), (int)Math.ceil(headerHeightOnPage));
g2.scale(scale,scale);
table.getTableHeader().paint(g2);//paint header at top
return Printable.PAGE_EXISTS;
} // end of print()
public static void main(String[] args) {
new PrintJTable();
}// end of PrintJTable
DisplayTable.java
import java.util.Vector;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.event.TableModelEvent;
public class DisplayTable extends AbstractTableModel {
Connection connection;
Statement statement;
ResultSet resultSet;
String[] columnNames = {};
Vector rows = new Vector();
ResultSetMetaData metaData;
String db_uname,db_passwd;
public DisplayTable() {
public void executeQuery(ResultSet resultSet) {
try {
metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
columnNames = new String[numberOfColumns];
// Get the column names and cache them.
// Then we can close the connection.
for(int column = 0; column < numberOfColumns; column++) {
columnNames[column] = metaData.getColumnLabel(column+1);
// Get all rows.
rows = new Vector();
while (resultSet.next()) {
Vector newRow = new Vector();
for (int i = 1; i <= getColumnCount(); i++) {
newRow.addElement(resultSet.getObject(i));
rows.addElement(newRow);
// close(); Need to copy the metaData, bug in jdbc:odbc driver.
fireTableChanged(null); // Tell the listeners a new table has arrived.
catch (SQLException ex) {
System.err.println(ex);
public void close() throws SQLException {
System.out.println("Closing db connection");
resultSet.close();
statement.close();
connection.close();
protected void finalize() throws Throwable {
close();
super.finalize();
// Implementation of the TableModel Interface
// MetaData
public String getColumnName(int column) {
if (columnNames[column] != null) {
return columnNames[column];
} else {
return "";
public Class getColumnClass(int column) {
int type;
try {
type = metaData.getColumnType(column+1);
catch (SQLException e) {
return super.getColumnClass(column);
switch(type) {
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
return String.class;
case Types.BIT:
return Boolean.class;
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
return Integer.class;
case Types.BIGINT:
return Long.class;
case Types.FLOAT:
case Types.DOUBLE:
return Double.class;
case Types.DATE:
return java.sql.Date.class;
default:
return Object.class;
// to make the cells editable
public boolean isCellEditable(int row, int column) {
try {
return metaData.isWritable(column+1);
catch (SQLException e) {
return false;
public int getColumnCount() {
return columnNames.length;
// Data methods
public int getRowCount() {
return rows.size();
public Object getValueAt(int aRow, int aColumn) {
Vector row = (Vector)rows.elementAt(aRow);
return row.elementAt(aColumn);
public String dbRepresentation(int column, Object value) {
int type;
if (value == null) {
return "null";
try {
type = metaData.getColumnType(column+1);
catch (SQLException e) {
return value.toString();
switch(type) {
case Types.INTEGER:
case Types.DOUBLE:
case Types.FLOAT:
return value.toString();
case Types.BIT:
return ((Boolean)value).booleanValue() ? "1" : "0";
case Types.DATE:
return value.toString(); // This will need some conversion.
default:
return "\""+value.toString()+"\"";
public void setValueAt(Object value, int row, int column) {
try {
String tableName = metaData.getTableName(column+1);
// Some of the drivers seem buggy, tableName should not be null.
if (tableName == null) {
System.out.println("Table name returned null.");
String columnName = getColumnName(column);
String query =
"update "+tableName+
" set "+columnName+" = "+dbRepresentation(column, value)+
" where ";
// We don't have a model of the schema so we don't know the
// primary keys or which columns to lock on. To demonstrate
// that editing is possible, we'll just lock on everything.
for(int col = 0; col<getColumnCount(); col++) {
String colName = getColumnName(col);
if (colName.equals("")) {
continue;
if (col != 0) {
query = query + " and ";
query = query + colName +" = "+
dbRepresentation(col, getValueAt(row, col));
System.out.println(query);
System.out.println("Not sending update to database");
// statement.executeQuery(query);
catch (SQLException e) {
// e.printStackTrace();
System.err.println("Update failed");
Vector dataRow = (Vector)rows.elementAt(row);
dataRow.setElementAt(value, column);
}Java 1.5 incorporates a very simple way to print from a JTable. I am using a mysql DB but it is the same concept. Review my code and let me know if you have any questions.
package emsmain;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.sql.*;
import java.text.MessageFormat;
import java.util.*;
import javax.print.*;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.*;
import javax.swing.JTable;
import javax.swing.table.*;
import java.awt.print.*;
public class TableFromDatabase extends JFrame implements ActionListener{
JButton jbtprint = new JButton("Print Report");
JTable Reporttable;
Connection conn = Connect_Database.getConnection();
public TableFromDatabase()
Vector columnNames = new Vector();
Vector data = new Vector();
try{
String query = null;
Statement ps = null;
ResultSet rs = null;
//Class Master List
if (Report_Menu.jrbMaster_list.isSelected()){
query =("Select * from students") ;
//Classes taken by student
if (Report_Menu.jrbClass_taken.isSelected()){
String taken = Report_Menu.jtfStudent.getText();
query = ("select program.course_num, course_name, course_start_date, course_stat_desc from registration, program where student_id = '"+taken+"' and program.course_num = registration.course_num");
//Birthday report
if (Report_Menu.jrbBirthday.isSelected()){
String birthday = (String) Report_Menu.jcb_birthday.getSelectedItem();
query = ("SELECT student_id, fname, lname, address, city, state_name, zipcode, dob FROM students where substring(dob, 6,2) = '"+birthday+"'");
//Course Catologue
if (Report_Menu.jrbCourseCatologue.isSelected()){
String course = (String) Report_Menu.jcbChooseCourse.getSelectedItem();
query = ("select course_name, course_length, course_cost, course_credits from course where course_name = '"+course+"'");
//Certification expiration report
if (Report_Menu.jrbExpiration.isSelected()){
String month = (String) Report_Menu.jcbMonth.getSelectedItem();
String year = (String) Report_Menu.jcbYear.getSelectedItem();
query = ("SELECT FNAME, LNAME FROM STUDENTS, REGISTRATION WHERE substring(expiration_date, 6,2) = '"+month+"' and substring(expiration_date, 1,4) = '"+year+"' and registration.student_id = students.student_id") ;
//Class Roster
if (Report_Menu.jrbRoster.isSelected()){
String c_number = Report_Menu.jtfClassNumber.getText();
query = ("Select course_name, course_start_date, fname, lname from program, registration, students where program.course_num = '"+c_number+"' and registration.student_id = students.student_id;");
//Squad list and counts
if (Report_Menu.jrbSquadCount.isSelected()){
query = ("SELECT Squad_Name, count(student_id) from students group by Squad_Name");
//Student List
if (Report_Menu.jrbStudent_list.isSelected()){
String Choose_month = (String) Report_Menu.jcbcourse_month.getSelectedItem();
String Choose_Course = (String) Report_Menu.jcbcourse_name.getSelectedItem();
query = ("select count(student_id) from (registration, program) where program .course_name = '"+Choose_Course+"' and substring(course_start_date, 6,2) = '"+Choose_month+"'and registration.course_num = program.course_num;");
ps = conn.createStatement();
//Run Selected Report
ps.execute(query);
rs = ps.executeQuery(query);
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
// Get column names
for (int i = 1; i <= columns; i++)
columnNames.addElement( md.getColumnName(i) );
// Get row data
while (rs.next())
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++)
row.addElement( rs.getObject(i) );
//add row data to JTable
data.addElement( row );
rs.close();
ps.close();
catch(Exception e)
JOptionPane.showMessageDialog(null,e.getMessage());
// Create Jtable with database data
Container c = getContentPane();
c.setLayout(new BorderLayout());
Reporttable = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane( Reporttable );
c.add( scrollPane );
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttonPanel.add(jbtprint);
c.add(buttonPanel,BorderLayout.SOUTH);
jbtprint.addActionListener(this);
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("Print Report")){
PrintForm();
public void PrintForm(){
try {
String name = null;
// Will display correct heading for print job
if (Report_Menu.jrbMaster_list.isSelected()){
name = "Master List";
if (Report_Menu.jrbBirthday.isSelected()){
name = "Birthday List";
if (Report_Menu.jrbClass_taken.isSelected()){
name = "Classes taken by Student";
if (Report_Menu.jrbCourseCatologue.isSelected()){
name = "Course Catalogue";
if (Report_Menu.jrbExpiration.isSelected()){
name = "Certification Expiration Report";
if (Report_Menu.jrbRoster.isSelected()){
name = "Class Roster";
if (Report_Menu.jrbSquadCount.isSelected()){
name = "Squad list with Student Counts";
if (Report_Menu.jrbStudent_list.isSelected()){
name = "Student count by Course";
// fetch the printable
Printable printable = Reporttable.getPrintable(JTable.PrintMode.FIT_WIDTH,
new MessageFormat(name),
new MessageFormat("Page - {0}"));
// fetch a PrinterJob
PrinterJob job = PrinterJob.getPrinterJob();
// set the Printable on the PrinterJob
job.setPrintable(printable);
// create an attribute set to store attributes from the print dialog
PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
// display a print dialog and record whether or not the user cancels it
boolean printAccepted = job.printDialog(attr);
// if the user didn't cancel the dialog
if (printAccepted) {
try {
// do the printing (may need to handle PrinterException)
job.print(attr);
} catch (PrinterException ex) {
ex.printStackTrace();
} finally {
// restore the original table state here (for example, restore selection)
} -
Problem in printing the JTable values
Dear Friends,
I have to print the JTable values (on paper using print dialogue box).
I'm using jtableObj.print to print the table values. But jtableObj.print takes more time to print the table values because it prints the values as a image(approximately 5 mins to print 10 pages).
My code is ,
boolean complete = tableObj.print(mode, header, footer, showPrintDialog, null, interactive,
null);Could anyone please tell me how to reduce the time?
Thanks in advanceHi again,
1. what problem are u facing ?
(there is no sapscript symbol / system symbol
for finding out the length )
(In abap u can use strlen)
2. data and gets trimmed
what is the meaning of it ?
3. do u mean to say that !
ABCDEF 123 45
GEF 123 45
is getting pritned like
ABCDEF 123 45 ?
GEF 123 45
4. If so , then use TABS
5. This happens because SPACE
is different in different varlues of
ABCDEF and GEF !
regards,
amit m.
Message was edited by: Amit Mittal -
How to make the row header of the JTable respond to mouse events?
Is there an easy way to enable the row header of a JTable so it listens to mouse events? I have put a button in the first cell of the row header but I can't click in it.
I'm asking for an easy way because I've seen some fairly complicated examples on the web that seem close to what I want but I was hoping something simple like getRowHeader().setEnabled(true) would do the trick for my case...What's your row header, another JTable or something else? Check out camickr's [url http://tips4java.wordpress.com/2009/07/12/table-button-column/]Table Button Column.
db
edit Or to get better help sooner, post a [url http://mindprod.com/jgloss/sscce.html]SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
Edited by: Darryl Burke -
Update JTable when an item is selected in a JComboBox inside the same JTabl
I created a JTable with a lookup JComboBox. I want to update values from the table when an item is selected in the ComboBox.
I tried all the events posible in JComboBox, but I can not fire to update the JTable.
Please if you have a how-to, (source) will help. Thanks.
Regards,
-RoryI tried that. But it only fires when the JComboxBox, lost the focus. And not in the "itemChange" event. How to do it width that event?
I want something like "intemChange" event, to fire the JTable.fireTableChangeUpdate(); ... I send the code.
* @author rory
public class PeriodenDauerGrid extends JPortSimTable implements Serializable, ActionListener {
* generated id
private static final long serialVersionUID = -5270969898251578932L;
public PeriodenDauerGrid() {
super();
@Override
protected void initComponent() {
super.initComponent();
setModel(new PeriodenDauerGridTableModel());
setDefaultEditor(String.class, new PeriodenCellEditor(this));
setDefaultRenderer(String.class, new PeriodenCellRenderer());
public void actionPerformed(ActionEvent e) {
// HERE should fire the table update.
// JOptionPane.showMessageDialog(null, "HOLITA!");
PeriodenDauerGridTableModel model = (PeriodenDauerGridTableModel) getModel();
model.fireTableDataChanged();
updateUI();
class PeriodenCellRenderer extends JLabel implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
setHorizontalTextPosition(SwingConstants.CENTER);
setHorizontalAlignment(SwingConstants.CENTER);
if (row == 1) {
setOpaque(true);
setBackground(GuiConstants.PANEL_COLOR);
} else {
setOpaque(false);
setBackground(GuiConstants.CELL_EDITOR_COLOR);
if (value instanceof Date) {
Date n = (Date) value;
// String.format(format, args)
String s = String.format("%1$td.%1$tm.%1$tY", (Date) value);
setText(s);
} else {
setText(value == null ? "" : value.toString());
return this;
class PeriodenCellEditor extends AbstractCellEditor implements TableCellEditor {
private JComboBox combo = new JComboBox(new String[] { "7", "84", "182", "364" });
private JTable table = null;
public PeriodenCellEditor(PeriodenDauerGrid table) {
combo.addActionListener(table);
this.table = table;
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
combo.setSelectedItem(value.toString());
return combo;
public Object getCellEditorValue() {
return combo.getSelectedItem();
} -
JTable header problem plz help me
hi
i want to insert JTable in JTextPane but I have two problems
i can't do this so any help plz
1- i want to insert table with header and allow the user to edit (write) on the table header when running the
program
2- i want to insert table without header but i want to make the table column still resizablehi
i want to insert JTable in JTextPane but I have two problems
i can't do this so any help plz
1- i want to insert table with header and allow the user to edit (write) on the table header when running the
program
2- i want to insert table without header but i want to make the table column still resizable -
How do i change the cursor on a jtable header when clicked for sorting?
here is my question, how do i change the cursor on a jtable header when I click the header for sorting?
I think it is suppose to be in the fragment of code where the header listener is implemented for sorting, but I'm not quite sure what is the exact component that holds everything so that i can change the cursor...
below is what I've tried, but it doesn't seem to work... thank you
public void addMouseListenerToHeaderInTable(JTable table) {
final TableSorter sorter = this;
final JTable tableView = table;
tableView.setColumnSelectionAllowed(false);
MouseAdapter listMouseListener = new
MouseAdapter() {
public void mouseClicked(MouseEvent e) {
TableColumnModel columnModel =
tableView.getColumnModel();
int viewColumn =
columnModel.getColumnIndexAtX(e.getX());
int column =
tableView.convertColumnIndexToModel
(viewColumn);
System.out.println("column = "+column);
if (e.getClickCount() == 1 && column != -1) {
System.out.println("Sorting ...");
Cursor oldCursor =
tableView.getRootPane().getCursor();
System.out.println("oldCursor.getType()
= "+oldCursor.getType());
if (oldCursor.getType() !=
Cursor.WAIT_CURSOR){
JComponent parentPane =
tableView.getRootPane();
parentPane.getContentPane().setCursor
(new Cursor(Cursor.WAIT_CURSOR));
parentPane.setCursor(new Cursor
(Cursor.WAIT_CURSOR));
Cursor newCursor =
parentPane.getCursor();
System.out.println("newCursor.getType
() = "+newCursor.getType());
int shiftPressed = e.getModifiers(
&InputEvent.SHIFT_MASK;
boolean ascending = (shiftPressed == 0);
//System.out.println("tableView.getRootPane()
is "+tableView.getRootPane().getRootPane());
sorter.sortByColumn(column, ascending);
tableView.getRootPane().setCursor(new Cursor
(Cursor.DEFAULT_CURSOR));
//System.out.println("Done sorting");
JTableHeader th = tableView.getTableHeader();
th.addMouseListener(listMouseListener);
}Hi,
Try setting the cursor for the table header.
table.getHeader().setCursor(Wait_Cursor);
Bala. -
all the links in the header of any websites are not working, the cursor is not changing into pointer and no way to click on any link located at the top of any website page. I reinstalled firefox and it s the same. No problem in others browser. the tool bar is working but not the links inside any web page located between the top 300px height.
So I can t tlog into any website, i cant write an email as the compose button is located in the top of the page.. Please help, i have all my bookmarks into my firefox...Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
*Don't make any changes on the Safe mode start window.
*https://support.mozilla.com/kb/Safe+Mode
*https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes -
Different JCombobox items in JTable for the same column
Hello Everyone,
I am reading from a file and displaying in a JTable. I want all cells in a specific column to be JComboBoxes but the items in the JComboBox differ from one cell to another, how can this be achieved?
The following is a snippet from the Sun tutorials,
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
comboBox.addItem("Knitting");
comboBox.addItem("Speed reading");
comboBox.addItem("Pool");
comboBox.addItem("None of the above");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
And hence every cell in the sportColumn has the exact same set of options in the JComboBox which is not what I want since I read from an external file.
Any help or sample code would be highly appreciated.
Thank you in advanceOverride getCellEditor(int row, int column) in JTable to control which editor gets used for which cell.
Maybe you are looking for
-
FIRST TIME RUNNING THE DEFAULT BSP APPLICATION IN ABAP
Hi BSP experts, I am happy to see many people are solving the problems on BSP in sdn. I am running the bsp application for the first time by taking the t-code se80 into consideration and executing the default bsp application given there.But I
-
Itunes 11.1.3 will not open after Mavericks installation.
After installing Mavericks, Itunes refuses to open. No errors or menu options display and library window does not open. Have tried reinstalling Mavericks with same issue, and wishing to avoid clean install.
-
Windows 7 Pulled from Retail?
As a microsoft developer (with MSDN Premium), a hardcore pc gamer and windows user, I can say with assurance that Windows 7 x64 is your best Desktop OS. Win7 is #1 in market share and far from outdated. Windows 8.x is a terrible desktop OS. Ther
-
I have my Mac Book Pro with the OS Yesomite since a month and I am feeling that my mac is getting slower than before a month. I want to install OS Lion on my mac. I think i have a DVD of OS Lion which comes when i bougnt Mac laptop in 2011. Should i
-
Access attribute of a context node in another context node of the same view
Hi all, I want to acess value of an attribute PERNR of context node CUSTOMERS in another context node AUTHENTICATION of the same view. A sample syntax would be helpful . Thanks,