Date time picker inside JTable - java

Is it possible to add a DateTimePicker to a JTable Cell.A particular column should be updated with date and time..Is it possible to add such a component to a JTable

The LGoodDatePicker library includes three TableEditor classes. These classes allow the programmer to add a DatePicker, a TimePicker, or a DateTimePicker, to the cells of a Swing JTable (or to a SwingX JXTable).
Fair disclosure: I'm the primary developer.
The picker classes can also be added to normal swing panels or other swing containers.
Here is an example of how to add a DateTimePicker to your JTable:
// Create a table.
JTable table = new JTable(new DemoTableModel());
// Add the DateTimeTableEditor as the default editor and renderer for
// the LocalDateTime data type.
table.setDefaultEditor(LocalDateTime.class, new DateTimeTableEditor());
table.setDefaultRenderer(LocalDateTime.class, new DateTimeTableEditor());
// Explicitly set the default editor and renderer for column index 0.
TableColumn column = table.getColumnModel().getColumn(0);
column.setCellEditor(table.getDefaultEditor(LocalDateTime.class));
column.setCellRenderer(table.getDefaultRenderer(LocalDateTime.class));
I've pasted screenshot below of the table editor demo, the picker components, and the full demo. Note that the library includes a separate demo for the table editors. It's in the Repository under this folder: "LGoodDatePicker/Project/src/main/java/com/github/lgooddatepicker/demo/TableEditorsDemo.java".
The library can be installed into your Java project from the project Release Page.
The project home page is on Github at:
https://github.com/LGoodDatePicker/LGoodDatePicker .
.

Yes it is. See this Swing Tutorial Track:
http://download.oracle.com/javase/tutorial/uiswing/components/table.html#combobox

Try to use the FLib-JCalendar component as an CellEditor in a JTable.
(and post the working example here if you made it work)

Yes, but you'll need to implement both TableCellRenderer and TableCellEditor. As suggested by #Jens Schauder, the tutorial may be helpful. You might also look at this tutorial based example using JCheckBox.

Simply use this code to set DatePicker in column 0:
TableColumn dateColumn = YOURTABLE.getColumnModel().getColumn(0);
dateColumn.setCellEditor(new DatePickerCellEditor());

By using the premise of Jens link and applying that logic with the below link, you can add a date time picker into a JTable, just be careful, combining JCheckbox, JCombobox and the date time picker into a JTable the focus get a little messy, but i believe it can be solved with a focus listener, it will just take some time t implement.
I am currontly working on such a Table render-er with will incorperate it all, i will post it online when im done.
Link: date and time picker in JAVA

Related

Options menu for one cell in java table

Welcome
In this table, I made the column mentioned cells editable to let the users make the needed value as they want ...
But they told me the values of this column can take just one of the values: 25,50,75,100, so, they asked me I make an options menu (like it is mention in the pic) allow them to choose directly the needed value and working fast.
So, how can I solve it, please!
(note: I'm working with java swing)
It's not the same question, but you can take a look on solution from below question:
How do I create a right click context menu in Java Swing?
you should create such listener, and add it to your Cell / Table.
you can take a look on below question to understand how to add listener to your Cell (it's not obvious :/)
JTable cell listener?

Eclipse Java JTable vs Table

For my company, I'm working on an Eclipse plugin which should do the following: show a table with sentences from the active editor that are incorrect in some way, accompanied by proper feedback. So far, so good.
However, sometimes the sentences/feedback are incorrect. I want a third column with checkboxes so that, when clicked, the related sentence/feedback combination is put in a different tab. Because I'm only programming in Java for 2 weeks now, I'm stuck: the plugin (written by my predecessor) is a class 'public class feedbackView extends ViewPart' using TabFolder and Table. But when I try to include checkboxes, all examples on the Internet use JTable. And I cannot get JTable to work in the current script and in the way I want (in Eclipse itself, instead of in a separate frame).
Ideally, I want Example of feedbackView with TabFolder. If in the 'Hide?' column the checkbox is checked, the sentence/feedback row should be transferred to the '||Hidden||' tab.
After this long introduction (hopefully clear), my questions:
Can I use Tabfolder/Table for this? Or
Should I use the JTable class (and how can I get this to work)?
Thanks in advance!
JTable is from Java Swing, with is the Java GUI component. Where Eclipse Table is the an Eclipse GUI component. There are two different world, for building GUI's in Java.
Warning: You can not mix these two different Java GUI libraries!

How to add button to row of JTable?

I have a Swing based application containing a JTable. Now I would like to allow each row to be updated or deleted, using a unique row ID. So I want to add an update and delete button to each row, which have the capability to support an ActionListener. However, I have no idea how to do this using NetBeans.
To display a button in a column you need to create:
a custom renderer to display the JButton
a custom editor to respond to the mouse click
Read the section from the Swing tutorial on How to Use Tables. The section on:
Using Custom Renders will explain the basics of using a renderer
Using Other Editors will explain the basics of using an editor
Working example are provided in the tutorial that you can download.
You can check out Table Button Column for one approach.
The code uses a single class to implement the custom renderer and editor that you will need for the column to display your text as a button.

Set number of options shown in JComboBox when used as JTable RowFilter

I'm trying to set the number of options shown in the JComboBox drop down list when it is used as a JTable RowFilter. Specifically, the filter on occasion can have many options and I'd like to show twice as many as the default (which appears to be 8). See this image:
Combox Box Example http://aalto.tv/test/combobox-image.png
As you can hopefully see, this ComboBox only shows 8 items and I would like to show more if there are more to be seen.
Having searched around the popular solution is to call "setMaximumRowCount" on the JComboBox, however this is having no effect.
Can any one point me in the right direction?
Many thanks for any and all help!
Cheers,
Alex
try the revalidate() (or repaint()) method after setting the rowcount;
if a setXX method does not generate an event to the component, then you have to manually reset it.
failing that, look at the source code of the setMaximumRowCount() method
JComboBox#setMaximumRowCount works for JTable / TableHeader and AutoComplete JComboBox in the JTable too

JTable sorting rows in Java 1.5

Is there a simple way to sort rows in a JTable with Java 1.5 (setAutoCreateRowSorter and TableRowSorter appear to be Java 1.6 features)?
Sorting in Java 1.5 is only possible via libraries.
E.g. use the JXTable mentioned from Kaarel or VLTable from here.
Another good library is glazedlists
which is also used in the Spring Rich Client project.
There are even ways to use Glazed Lists with JXTable
Use the JXTable from the SwingX project, see e.g.
SwingLabs: How to Use the SwingX JXTable: Sorting Rows
JXTable requires a big package, and is difficult to get the right version for. (no higher than version 1.0 for Java 1.5).
Try instead TableSorter.java. Get it at:
http://ouroborus.org/java/2.1/TableSorter.java
And insert it in your project.
Now you wrap your tableModel in an instance of TableSorter, and instert that into the JTable. TableSorter acts as a "go-between" the JTable-instance and your tableModel.
Use it something like this (code untested):
JTable myTable = new JTable();
TableSorter mySorter = new TableSorter(myTableModel, myTable.getTableHeader());
myTable.setTableModel(mySorter);
You can set sprting programmatically like this:
mySorter.setSortingStatus(0,TableSorter.ASCENDING);
Try tweeking MouseHandler.mouseClicked() to get it to skip the NOT_SORTED option in the clicking order, and mess with renderers for e better column header and placing and visibility of triangle.

Categories

Resources