Filtering the rows of a JTable based on JCombobox selection
Hi,,,
I write an application where I have a combobox contains the JTable first column data when i click on the item it should give me the rows, which contains the selected item as their first column data. I am enable to get the list like that, please, help me in this.........................................
Thanks In Advance,
Sun_sgrk
Hi Albert,
I write the code like this.............., please, check it, if I am following any where wrong let me know.......
JComboBox filterCb=(JComboBox)evt.getSource();
if(filterCb==filterComboBox){
for(int i=0;i<wtOb.length;i++){
for(int j=0;j<4;j++){
if(wtOb[0].toString()==filterComboBox.getSelectedItem())
System.out.println(""+wtOb[i][j]);
This code I written in netbeans, when I am printing the values of wtOb[i][j] in console its getting the rows, suppose I am selecting the topic as GeneralTopic then its givining me the output as-----
GeneralTopic
Dealer5
Player3
BlackJack2
GeneralTopic
Dealer7
Player6
BlackJack
but I am getting the trouble when i want to show these rows only in my table, please, give me any suggestion or any help to resolve it. I tried with table.setModel also but its not working.
Regards,
sun_sgrk
Similar Messages
-
How to clear the rows in a jTable
Can anyone tell me how to clear the contents of all the rows in a jTable?
This is how I did. Posting the same.
jTable1.selectAll();
int[] array = jTable1.getSelectedRows();
for(int i=array.length-1;i>=0;i--)
DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
model.removeRow(i);
Regards. -
How do you make the rows in a JTable uneditable.
Hi
Does anyone knows how to make the rows in a JTable uneditable.
--kirkHi,
implement a TableModel, e.g AbstractTableModel and use it to initialise
your table. (JTable aTable = new JTable(myAbstractTableModel))
And if you want your table to be editable implement isCellEditable() in your table model, and let it return true. If not let it return false, or don't implement it att all. -
Changing the color of the column in a JTable based on the selection (mouse)
Hi,
I want to change the color of all the cells in a column based on the mouse clicked event.
I have managed to select the entire column. And, even, I have found a working example in the internet. But I don't understand why in my case it doesn't work.
This is the code (an inner class for a TableCellRenderer):
class MCTableCellRenderer extends JLabel implements TableCellRenderer {
private static final long serialVersionUID = 1L;
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
setFont(table.getFont());
if(value instanceof Double){
setHorizontalAlignment(SwingConstants.RIGHT);
DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance();
numberFormat.applyPattern("#######.#");
String val = numberFormat.format(value);
setText(val);
if(isSelected){
setBackground(Color.RED);
System.out.println("is selected");
else{
setBackground(Color.BLACK);
System.out.println("is not selected");
return this;
}I have set opacity to true for the contentPane, but without any result.
Any advice will be very apreciated.Problem solved.
My Renderer should have extended the abstract class DefaultTableCellRenderer.
class MCTableCellRenderer extends DefaultTableCellRenderer { -
Setting colors of the rows of a JTable
Hi,
How can we set multiple colors(foreground) for multiple rows in a JTable?. (i want to set the color of the row depends on the value of a column. Foe example if the value of a particular column is "x" then i want to set the color of that particular row as "RED" or if the value of that column is "y" then i want to set the color of the column as "GREEN". )Try this:
* Method to set custom cell renderer
*Adopted from
* http://javaalmanac.com/egs/javax.swing.table/Stripe.html
JTable theTable = new JTable() {
public Component prepareRenderer(TableCellRenderer renderer,
int row, int col) {
Component c = super.prepareRenderer(renderer, row, col);
//Example assumes the column number is 1 and value is "Critical"
if (theTable.getValueAt(row, 1) != null) {
if (theTable.getValueAt(row, 1).equals("Critical")) {
if (col == 1) {
c.setForeground(Color.red);
c.setBackground(new Color(255, 255, 204));
c.setFont(new java.awt.Font("MS Sans Serif", 1, 11));
return c;
}; -
Sorting the Rows in a JTable Component Based on a Column
Hi Masters..would like to have your valuable help and suggestion..i am using jdk1.4.i have jtbale and would like to have one column data in sorted way...
just i am enclosing my code in tha i am using Collections.sort(data, new ColumnSorter(colIndex, ascending)); but that compare of that comparator is not at woring that data is not getting soretd.
here data is the jtable complete data.
Main java file:
package com.ibm.sort;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class SimpleTableDemo extends JPanel {
private boolean DEBUG = false;
int colIndex;
boolean ascending;
DefaultTableModel model = new DefaultTableModel();
public SimpleTableDemo() {
super(new GridLayout(1,0));
String[] columnNames = {"First Name","Last Name","Sport","# of Years","Vegetarian"};
Object[][] data = {
{"Mary", "Campione","Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath","Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour","Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)}
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 80));
table.setAutoCreateColumnsFromModel(false);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
sortAllRowsBy(model, 1, true);
public void sortAllRowsBy(DefaultTableModel model, int colIndex, boolean ascending) {
Vector data = model.getDataVector();
System.out.println("SimpleTableDemo.sortAllRowsBy()11111");
Collections.sort(data, new ColumnSorter(colIndex, ascending));
//Collections.sort(data);
//Arrays.sort(data, new ColumnSorter(colIndex, ascending));
System.out.println("SimpleTableDemo.sortAllRowsBy()2222");
model.fireTableStructureChanged();
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("SimpleTableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
SimpleTableDemo newContentPane = new SimpleTableDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
Second FIle which has sorting :
* Created on Jun 21, 2008
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
package com.ibm.sort;
import java.util.Comparator;
import java.util.Vector;
// This comparator is used to sort vectors of data
public class ColumnSorter implements Comparator {
int colIndex;
boolean ascending;
ColumnSorter(int colIndex, boolean ascending) {
System.out.println("ColumnSorter.ColumnSorter(---colIndex--:"+colIndex+" ,ascending: "+ascending);
this.colIndex = colIndex;
this.ascending = ascending;
System.out.println("ColumnSorter.ColumnSorter()");
public int compare(Object a, Object b) {
System.out.println("compare-----:");
Vector v1 = (Vector)a;
Vector v2 = (Vector)b;
Object o1 = v1.get(colIndex);
Object o2 = v2.get(colIndex);
System.out.println("ColumnSorter.compare(): -o1- :"+o1+" ,o2: "+o2);
// Treat empty strains like nulls
if (o1 instanceof String && ((String)o1).length() == 0) {
o1 = null;
if (o2 instanceof String && ((String)o2).length() == 0) {
o2 = null;
// Sort nulls so they appear last, regardless
// of sort order
if (o1 == null && o2 == null) {
return 0;
} else if (o1 == null) {
return 1;
} else if (o2 == null) {
return -1;
} else if (o1 instanceof Comparable) {
if (ascending) {
System.out.println("ascending-->ColumnSorter.compare()-((Comparable)o1).compareTo(o2): "+(((Comparable)o1).compareTo(o2)));
return ((Comparable)o1).compareTo(o2);
} else {
System.out.println("Desending-->ColumnSorter.compare()-((Comparable)o1).compareTo(o2): "+(((Comparable)o1).compareTo(o2)));
return ((Comparable)o2).compareTo(o1);
} else {
if (ascending) {
System.out.println("ColumnSorter.compare()---o1.toString().compareTo(o2.toString())---: "+(o1.toString().compareTo(o2.toString())));
return o1.toString().compareTo(o2.toString());
} else {
return o2.toString().compareTo(o1.toString());
Please help is deadly needed.
thanks in advance!!!Learn to use code tags.
Learn to use google.
http://www.google.com/search?q=java+sort+rows+jtable&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a -
How to display all the rows in a JTable ???
Hi,
i want to display blank lines in a JTable if there is not enough rows to fill in it. For the moment, there is nothing in the JTable if i have nothing in my tables. Where am i wrong ??
Thanks !!hi,
use a contructor for jtable with the parameter rowcount or
define a tablemodel class extends from abstract tablemodel mit the method int getRowCount()
{ return xxx;}
table.setModel(mymodel); -
Filtering the contents of one alv based on another ALV's filter
Hi,
I have used a tab element within which i have two tabs.each tab has an alv table.
Is it possible to restrict the entries of one alv table based on enrties from another alv table(both the alv tables will have some common fields).for example I have filtered entries in alv1 based on field1 .when i go to alv2 entries should be restricted on the field1 (common field)
Thanks
Bala Duvvuri
this is the answer
refer SALV_WD_FILTER_UI
Edited by: Bala Duvvuri on Oct 4, 2011 1:20 AMhi Mohamed,
Go through this links ,
<a href="http://help.sap.com/saphelp_nw70/helpdata/en/95/92b2f7d2f14a6da7a8b5d66808d1f6/content.htm">Portal Display Rules</a>
<a href="http://help.sap.com/saphelp_nw70/helpdata/en/4b/29cf122f414721964269e1b675d62c/content.htm">Rulecollection</a>
Regards,
Malini.V -
How can I add rows to a JTable based on an Abstract Table Model?
I have done this ...
public class myui extends JPanel {
private AbstractTableModel jTable1Model;
blah blah
jTable1Model = new AbstractTableModel() {
String[] column = new String[]{"TID", "Name", "Address"};
Vector<Vector<Object>> table = new Vector<Vector<Object>>();
@Override
public int getRowCount() {
return table.size();
@Override
public int getColumnCount() {
return column.length;
@Override
public String getColumnName(int col) {
return column[col];
@Override
public Object getValueAt(int row, int column) {
return table.get(row).get(column);
@Override
public void setValueAt(Object value, int row, int column) {
table.get(row).set(column, value);
fireTableCellUpdated(row, column);
public void insertRow() {
Vector<Object> columns = new Vector<Object>();
columns.add(null);columns.add(null);columns.add(null);
table.add(columns);
fireTableRowsInserted(0, table.size());
blah blah
public synchronized void ImportVisitorDataToJTable1(Object value, int row, int col) {
jTable1Model.InsertRow(); <-----///// This line not being recognised as a valid member function call
jTable1.setValueAt(value, row, col);
}I thought to insert a row I can define a function in the abstracttablemodel class and then instantiate the class and override or create new methods that I can use.
But after instantiating the class and overriding appropriately and adding the insertRow function, when I try to use it in ImportVisitorDataToJTable1 as seen above its not being recognized as a funtion of jTable1Model1. respect naming conventions. Example: myui --> MyUI, ImportVisitorDataToJTable1 -->importVisitorDataToJTable1
2. convert Anonymous to Member: AbstractTableModel --> MyTableModel
3. row parameter makes no sense here as it depends on current row count:
public synchronized void importVisitorDataToJTable1(Object value, int col) {
int row = jTable1Model.getRowCount();4. here is a more adequate "fireTable.."-call for insertRow:
fireTableRowsInserted(table.size() - 1, table.size() - 1);
5. check if you can take advantage using DefaultTableModel as suggested by Maxideon. -
Hi all,
I have a requirement where
i need to select a LOV value
and based on that value the field next to it should be generated......
in brief suppose i have a field name EMPLOYEE NO as lov........
as i select the employee number the field next to it assume EMPLOYEE NAME should be retrieved based on the employee number selected..
hope i am clear
waiting for ur responce.....
DEV......Hi,
Assuming you are having two fields on the page. One LOV for empID (ID: empIDV) and messageTextInput for emp Name (ID: empNameV)
1) Create a VO for your LOV having a query like SELECT emp_num, emp_name FROM employees;
2) Create region for LOV using table using wizard based on the VO created above (choose emp_num as messageStyledText and emp_name as formValue). Also make search allowed true for emp_num.
3) Create a LOV map1:
LOV region item: empId
Return item: empIDV
Criteria item: empIDV
4) Create lovMap2:
LOV region item: empName
Return item: empNameV
Also try to implement dependent LOVs : http://sushantsharmaa.blogspot.in/2012/12/10-dependent-lov-in-oaf.html
--Sushant -
How to change the values in an LOV based on values selected in another LOV
Hi,
I have a requirement in ADF where there are two LOVs. Based on the values that I select in the 1st LOV, the values in the second LOV should change dynamically.
Also, the 1st LOV accepts 3 values, for every value I select, a different query is executed to populate the 2nd LOV.
I have a rough thought that I can use 3 different read only view objects containing these 3 queries. And based on the value I select in the 1st LOV I can execute the corresponding View object from the backing bean. But my doubt is how to link the results of that query that is executed to populate the 2nd LOV.
Thanks in advance.
Edited by: 886591 on Sep 21, 2011 4:48 AMHi Brisk,
Thanks for your reply.
The link that you have provided explains how to disable and enable the other LOVs based on a parent LOV. But in my case there are two Select One Choice fields i.e. the dropdowns (sorry that I addressed it as LOV in my previous post which might be confusing). There are 3 static values in the parent dropdown where each of them are associated with a different query. for e.g if the three values in the drop down are A, B and C; if i select A, then query associated to A should be executed ; if i select B, then query associated to B should be executed and if I select C, query associated to C should be executed. Then the output attribute of that query should be populated in the child dropdown.
Please let me know about the solutions to this.
Thanks,
Kavitha -
Hello to everybody. I would like to ask you if there is a way to change the order of the rows in a JTable by selecting them and dragging with the mouse just as you can do with columns.
Best regards.
AlessandroCheers Richard,
I'm using TableSorter which is part of the TableSorterDemo in How To Use Tables in the Sun Java tutorial if you want to look - it works fine within the demo. I'm afraid I'm fairly new to java so I'm not sure where to look for the problem. I think I'll try using the default tablemodel, see if that works and then add stuff until it all goes wrong again! Is this sensible? Any more ideas?
Thomas -
Use a variable to define the row number in a Range ("???").select
Dim r as integer
r=5
Range("G r").select
This stalls with 'Range' _Global fail
I want to manipulate r (the row that logic produces) and use to select a cell
Help...fixRe: specify a range
Dim r As Long
r = 5
Cells(r, "G").Select
-or-
Range("G" & r).Select
Jim Cone
Portland, Oregon USA
free & commercial excel programs (n/a xl2013)
https://jumpshare.com/b/O5FC6LaBQ6U3UPXjOmX2 -
Hide multiple rows in a dynamic table based on the row value.
Hi,
I need to hide multiple rows in a dynamic table based on the specific value of that row.
I cant find the right expression to do that.
please helpGo to the Row Properties, and in the Visibility tab, you have "Show or hide based on an expression". You can use this to write an expression that resolves to true if the row should be hidden, false otherwise.
Additionally, in the Matrix properties you should take a look at the filters section, perhaps you can achieve what you wish to achieve through there by removing the unnecessary rows instead of just hiding them.
It's only so much I can help you with the limited information. If you require further help, please provide us with more information such as what data are you displaying, what's the criteria to hiding rows, etc...
Regards
Andrew Borg Cardona -
I have a status of completed and a date field in the dataset. The date field is either empty or contains a date. All 2015 dates are holding dates.
So how can I limit the report to only pull completed status with an empty date or a holding date?
I have not been able to set an OR option on a date field filter and if I add two filters on the date column one for empty one for > 12/31/2014 then it treats it as an "and" and pulls nothing from the list I have in sharepoint.
any help will be appreciated.Hi MB,
In Reporting Services, the relationship of filters is “And”, and there is no option to change the relationship from “And” to “Or”. While we can use “or” operator within the expression to create one filter to integrated all filters to work around this
issue.
We can add a filter as follows in the dataset to limit the rows in your report:
Expression: =Fields!date.Value is nothing or Fields!date.Value>"12/31/2014" Type: Boolean
Operator: =
Value: true
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
If you have any feedback on our support, please click
here.
Katherine Xiong
TechNet Community Support
Maybe you are looking for
-
Is is possible to re-download everything I have ever purchased from iTunes?
My computer and iphone were stolen. Is it possible to re-download everything I ever purchased from iTunes?
-
Print options not working in CP7
I am unable to make handouts, save to pdfs, all print options. I get the same error message as addressed in http://helpx.adobe.com/captivate/kb/cant-publish-ms-word-captivate.html Please help.
-
How we can add the 2 buttons on the alv out screen.
I have a requirement, i want to add two buttons on the application bar on the ALV report out. with the use of grid functional module. for example: i want to buttons details and balance on the ALV output screen. if i click on detail it will display th
-
I found cooliris previews, piclens as culprit.. I removed them all working ok..!
-
Clear Open Reservations in CO11n
Hi All.... I have a doubt on clear open reservations check box in colln. Please explain how it works.. if it is ticked and unticked in both cases what happens?? I tried GI with/without ticking the clear open reserv. in both cases the material is issu