How can i set color some rows in jtable
hi all,
i have table with two cols one is id and other name
i have array of id, i want set color for only those rows in an array
i tried with the following code but only one row is seting why it is not setting
the other rows? or this is the worg way what i did?
model = new DefaultTableModel(data, header);
table = new JTable(model){
int mostUsedCols[] = 151,80,185,90,88,95,137,152,153,181,178,179,180,107};
public Class getColumnClass(int column)
return getValueAt(0, column).getClass();
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
Component c = super.prepareRenderer(renderer, row, column);
int id = Integer.parseInt(tblLedgerAccounts.getModel().getValueAt(row, 0).toString());
for(int j=0; j<mostUsedCols.length;j++){
c.setBackground( id == mostUsedCols[j] ? Color.LIGHT_GRAY : Color.WHITE );
return c;
}help me to solve this problem
thanks
daya
hello,
thanks,
i have table 2 cols(say for ex) 1st column is name and other one is
id, and i have some array of id's, i need to set the color for these rows
and remainings rows are defalut color (white).
I doubt that you need the
else
c.setBackground( Color.WHITE );if i did't set like this the entire table get gray.
>
since the color should be set to the default by the
super.prepareRenderer(...) method. In fact this code
would override the default row selection coloring.
But maybe I don't understand your requirement. You
notice my original example always to check to make
sure the row is not selected before changing the
background color.here is the demo, i comment this line what will happen c.setBackground( Color.WHITE );
if not doing right than suggest me.
import java.awt.Color;
import java.awt.Component;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
public class TableColor extends JFrame {
public TableColor()
Vector header = new Vector();
Vector data = new Vector();
header.addElement("ID");//0
header.addElement("Name"); //1
header.addElement("village"); //2
Vector v = new Vector();
v.addElement(new Integer(1));
v.addElement("daya");
v.addElement("DVB");
data.addElement(v);
Vector v1 = new Vector();
v1.addElement(new Integer(2));
v1.addElement("raju");
v1.addElement("DVBs");
data.addElement(v1);
Vector v2 = new Vector();
v2.addElement(new Integer(3));
v2.addElement("James");
v2.addElement("sdf");
data.addElement(v2);
Vector v3 = new Vector();
v3.addElement(new Integer(4));
v3.addElement("Naga");
v3.addElement("DVBsadf");
data.addElement(v3);
Vector v4 = new Vector();
v4.addElement(new Integer(5));
v4.addElement("xyz");
v4.addElement("asdf");
data.addElement(v4);
DefaultTableModel tblModLedgerAccounts = new DefaultTableModel(data, header);
JTable tblLedgerAccounts = new JTable(tblModLedgerAccounts){
int mostUsedCols[] = {2,4,5};
public Class getColumnClass(int column)
return getValueAt(0, column).getClass();
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
Component c = super.prepareRenderer(renderer, row, column);
int id = Integer.parseInt(getModel().getValueAt(row, 0).toString());
for(int j=0; j<mostUsedCols.length;j++){
if(id == mostUsedCols[j]){
c.setBackground(Color.lightGray);
break;
// else
// c.setBackground(Color.WHITE);
return c;
JScrollPane scrollPaneLedgerAccounts = new JScrollPane(tblLedgerAccounts);
tblLedgerAccounts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.getContentPane().add(scrollPaneLedgerAccounts);
setVisible(true);
pack();
setTitle("Table Color");
setDefaultCloseOperation(EXIT_ON_CLOSE);
public static void main(String args[]){
new TableColor();
}thanks
daya
Similar Messages
-
How can you set the max row for a 'open cursor' in a stored proc?
I would like to know how can you set the maximum amount of row returned in a resultset coming from a stored proc?
You can do it via JDBC with cStatement.setMaxRows(10); but it works only for select that you do via JDBC...
I would like the same functionality using open cursor inside a stored proc...
Thanks...is "where ROWNUM <= 10" the equivalent of "cStatement.setMaxRows(10);" because the ROWNUM as problem with the ORDER BY clause and the setMaxRows() as no problem...
-
How can i set the alternating colors for a table rows
Dear All,
Please any one help me how can i set the Alternating colors for Table Rows.
i created a theam there i set the background alternating color to brown and i set the table design properity to alternating. but it is not reflecting.Hi,
The design property in Table properties should work for your requirement. Select "alternating" value for design.
Please see the API below:
design
Determines the appearance of the table. The property design can take the following values and is represented by enumeration type WDTableDesign.
alternating - The table rows are displayed alternately in a different color.
standard - The table background has one color. The individual table rows are displayed with grid net lines.
transparent - The table background is transparent. The individual table rows are displayed without grid net lines.
Check whether you have changed the right property or not? Also table should contain more than one rows to test this scenario.
Regards,
Jaya.
Edited by: VJR on Jun 17, 2009 6:43 PM -
How can i set background color of child window in jdk 1.6
Hi friends i hv devoloped simple java app using javax.swing.JFrame in which on click button event i open new child window using JFrame to draw some image.
i set childs background color as setBackground(Color.lightGray);
but the problem is,child window takse its background color same as its parent window.(i.e. main window's color or desktop ).i get this problem in jdk 1.6.but it is working fine in jdk 1.5.
how can i set background color of child window in jdk 1.6 .
plz solve my problem.
thanks in advanced.Mo,
Call me old fassioned, but I simply refuse to demangle SMS speak.
You've got a whole keyboard, so learn how to use it.
Keith. -
How to set background color of row in JTable
Hi,I want to set different background color to rows in JTable according to some value in the this row.
eg.
no name isGood
1 aaa yes (this row's background color is red)
2 bbb no (this row's background color is blue)
3 ccc yes (this row's background color is red)
4 ddd yes (this row's background color is red)
5 eee no (this row's background color is blue)
thanksthanks!*_*
-
How to set background color in row of JTable ?
i am new in java please tell me about How to set background color in row of JTable ? please example code. Thnak you.
Here is an example: http://www.javaworld.com/javaworld/javaqa/2001-09/03-qa-0928-jtable.html
For more info on how to use tables read the swing tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
ICE -
How can I set the default print settings of my document as color. I want the default print setting to be color when someone opens a document. similar to duplex print preset is there a color print preset?
Hi,
Try saving your settings as a Preset by clicking the Preset drop down and then select Save Current Settings as a Preset.
Next try changing the settings by selecting the saved preset.
That allow saving the settings for a specific printer, I assume it may also allow selecting these settings for another printer. -
How to set color of our specified JTable's row
i need to set color of our specified JTable's row.so send the coddings of that part.
i need to set color of our specified JTable's row.so
send the coddings of that part.I think you misunderstand how this forum works...
If you have a problem, you post your problem here with example code which demonstrates said problem...
The people here then attempt to help you if they want to.
You do not post demands for code examples -
Hi Edge community, How can I set a custom colors
Hi Edge community,
How can I set a custom colors & font size
to the Adobe Edge Animate CC 2014
work space (stage, time lone, tools, etc...)
to get something close to this?
http://www.vrmall.eu/vr/EDGE_WORKSPACE_BLACK_n_WHITE/EDGE_WORKSPACE_BLACK_n_WHITE_r.01.jpg
Thanks a lot for Your time and help.Hi Robyn_cpl,
thanks for the useful link - based on this I decided to
purchase the PDF of Adobe Edge Animate: The Missing Manual
by Chris Grover. Good book indeed, work space panels resizing
and docking are covered, but there is nothing on colors&fonts...
I've been searching intro's, tut's, forums on Edge, but no hint
on this... But I keep searching You Tube, Google, etc...
I'm intended to submit the subject to Adobe Edge Support.
Thanks again for Your attention -
How can I make the current row in a different color in ADF Table 10.1.3
Hi all
in JDeveloper 10.1.3 ADF Table ,
How can I make the current row in a different color ?
thanksAnd what exactly would "the component" be?
I tried the af:outputText, but it just creates a <span> around the value of the cell, and if I try the af:column it just won't use it at all!
Any suggestions? -
Hi please help me , how can i set my ringing tone on my iPhone from my playlist. I wanna set some normal music from my floder not some ringing tones from iPhone origin . Please help me . Thank you
You need to make your own ringtones in iTunes then sync them to your phone. Follow the directions here:
http://osxdaily.com/2010/09/04/make-free-iphone-ringtones-in-itunes-10/ -
How Can I set up a JTable columns?
Dear All,
How can I set up my JTable columns to have the amount the user specifies?
for example when the user types in 50 in JTextField 1 I want the JTables columns to then set to 50.
How can this be done?
Thanks
lol
import javax.swing.*;
import javax.swing.table.TableModel;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class si1 extends javax.swing.JFrame implements ActionListener {
JTextField name = new JTextField(15);
JTextField name1 = new JTextField(15);
public si1() {
super("DataBase Loader");
setSize(1025,740);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
JPanel pane1 = new JPanel();
JPanel pane2 = new JPanel();
JPanel pane3 = new JPanel();
JPanel pane4 = new JPanel();
pane.setLayout(new GridLayout(20,1));
pane1.setLayout(new BorderLayout());
int j=10;
String[][] data = new String[j][2];
for (int k=0; k<j; k++){
String[] row = {"",""};
data[k] = row;
String[] columnNames = {"First Name", "Last Name"};
JTable perstab = new JTable(data, columnNames);
perstab.setGridColor(Color.yellow);
perstab.setPreferredScrollableViewportSize(new Dimension(500,500));
JScrollPane scrollPane = new JScrollPane(perstab);
pane1.add(new JPanel(), BorderLayout.EAST);
JButton btn = new JButton("What are the names?");
btn.addActionListener(this);
btn.putClientProperty("DATABASE", perstab);
pane1.add(new JPanel().add(btn), BorderLayout.SOUTH);
pane2.add(name);
pane3.add(name1);
pane.add(pane2);
pane.add(pane3);
pane1.add(pane, BorderLayout.WEST);
pane4.add(scrollPane);
pane1.add(pane4, BorderLayout.CENTER);
setContentPane(pane1);
show();
public static void main(String[] args) {
si1 frame = new si1();
frame.setVisible(true);
public void actionPerformed(ActionEvent e) {
JTable table = (JTable)((JButton)e.getSource()).getClientProperty("DATABASE");
TableModel model = table.getModel();
int count = model.getRowCount();
String[] firstnames = new String[count];
String[] lastnames = new String[count];
for (int i=0; i < count; i++) {
firstnames[i] = (String)model.getValueAt(i, 0);
System.out.println("first name at row " + i + ": " + firstnames);
lastnames[i] = (String)model.getValueAt(i, 1);
System.out.println("lastname name at row " + i + ": " + lastnames[i]);As you can see I have tried this, but no success.
If I am doing something wrong please accept my apology, and address me in the right direction.
Thanks
Lol
import javax.swing.*;
import javax.swing.table.TableModel;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class si1 extends javax.swing.JFrame implements ActionListener {
JTextField name = new JTextField(15);
JTextField name1 = new JTextField(15);
public si1() {
super("DataBase Loader");
setSize(1025,740);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
JPanel pane1 = new JPanel();
JPanel pane2 = new JPanel();
JPanel pane3 = new JPanel();
JPanel pane4 = new JPanel();
pane.setLayout(new GridLayout(20,1));
pane1.setLayout(new BorderLayout());
int j=10;
String[][] data = new String[j][2];
for (int k=0; k<j; k++){
String[] row = {"",""};
data[k] = row;
String[] columnNames = {"First Name", "Last Name"};
JTable perstab = new JTable(data, columnNames);
((DefaultTableModel)perstab.getModel()).setColumnCount(Integer.parseInt(name.getText()));
perstab.setGridColor(Color.yellow);
perstab.setPreferredScrollableViewportSize(new Dimension(500,500));
JScrollPane scrollPane = new JScrollPane(perstab);
pane1.add(new JPanel(), BorderLayout.EAST);
JButton btn = new JButton("What are the names?");
btn.addActionListener(this);
btn.putClientProperty("DATABASE", perstab);
pane1.add(new JPanel().add(btn), BorderLayout.SOUTH);
pane2.add(name);
pane3.add(name1);
pane.add(pane2);
pane.add(pane3);
pane1.add(pane, BorderLayout.WEST);
pane4.add(scrollPane);
pane1.add(pane4, BorderLayout.CENTER);
setContentPane(pane1);
show();
public static void main(String[] args) {
si1 frame = new si1();
frame.setVisible(true);
public void actionPerformed(ActionEvent e) {
JTable table = (JTable)((JButton)e.getSource()).getClientProperty("DATABASE");
TableModel model = table.getModel();
int count = model.getRowCount();
String[] firstnames = new String[count];
String[] lastnames = new String[count];
for (int i=0; i < count; i++) {
firstnames[i] = (String)model.getValueAt(i, 0);
System.out.println("first name at row " + i + ": " + firstnames);
lastnames[i] = (String)model.getValueAt(i, 1);
System.out.println("lastname name at row " + i + ": " + lastnames[i]); -
How can I set PCTUSED and PCTFREE in Warehouse databases?
Hi,
There are many Schemas in our database and some are used for OLTP and some others are used for Warehouse. Also our tablespaces are Local Managed.
Could you help me please how can I set PCTUSED and PCTFREE for Warehouses and OLTP.
What are your suggestions? What should be optimum?
DB version is 9.2.0.8.
thanks & regardsIf you are using locally managed tablespaces with ASSM then the pctused parameter would no longer apply. In all cases dictionary vs locally managed with or without ASSM you should set pctfree based on how much of the data row column values are present at initial row insertion and how likely any column is upated to a larger size after initial row insertion.
In a warehouse I would expect most of the tables to have 100% of the row data present at initial insert and for the data to never be updated. For tables meeting this requirement a pctfree of 3 - 5% would likely be a good choice. I never like to use 0% since the day may come when you add another column to the table.
With OLTP tables the ideal pctfree value varies more from table to table. Most table so seem to work well enought with the default 10% but I have seen tables that need 50% pctfree to prevent row migration since only the key column values existed at initial insert and most all the other column data was added later.
Where ASSM is not in use I like to set pctused to 95 - pctfree. Over the last 15 years I am not sure I ever found a need to change the pctused from this once set. I have set a lot of tables up over the years from the old default of 40% to use 60% and 80% before resetting everything during a server platform migration as I mentioned above.
HTH -- Mark D Powell -- -
How can I set my WebI filters to Null and not Null
Folks,
I have created a report in WebI and now I am to set up some filters as Null and some Not Null.
How can I set my WebI filters to Null and not Null?
Regards,
Bashir AwanHi,
As you said you could do it at the report level and also at the universe level.
One more way is to create the filters in the universe levele and add them in thequery filter.
Ex: in the filter you need to write :
Column1 is null and and column 2 is not null etc.
Hope this will help.
If this did't solve your problem then please explain it in detail.
Cheers,
Ravichandra K -
I have an iPad with IMAP email accounts set up but can find no "inbox, drafts, trash" folders for each email account anywhere on my iPad or in Mac Mail. How can I set them up? I can't find anyway to set them up anywhere. Thanks
Hello blu monkey,
I found some resources that I think might help with the visibility of your IMAP email folders on your iPad and Mac.
On your iPad, you may need to follow the steps in this article to make sure your folders are visible:
iOS: If IMAP Mail folders are not visible
http://support.apple.com/kb/HT1393
On your Mac, I am not sure if you have the sidebar enabled, but you can enable it using the steps in the article below. When this is showing, you should see your email account listed near the bottom with a triangle next to it. When the triangle is pointing down, it should show your folders:
Mail (Mountain Lion): Show or hide the sidebar
http://support.apple.com/kb/PH11763
Thank you for using Apple Support Communities.
Best,
Sheila M.
Maybe you are looking for
-
Security update fixes ACL problems, almost
So far when running disk permissions, I've had one iMac C2D have no problems reported and the other iMac C2D only have ACL issues on /Library
-
Satellite P300-18M - Is using the card reader for Vista Ready Boost OK?
Hi there, I have a P300-18M, and, due to getting a new phone, have an 8GB Micro SD Card spare. I have put this in the card reader, and I am currently using it for Ready Boost, even though I have 3GB of RAM, there is definately a performance boost...
-
J1INCHLN - Create Remittance Challan
At the time of posting J1INCHLN - Create Remittance Challan Following error i m getting Number key not found Message no. 8I705 Plz give me the sollution. I am new to Withholding tax.
-
QM: Copying inspection results to another lot
Experts, has anyone experience with automatic copying closed inspection results from one inspection lot to another one? Rgds
-
Failed to navigate from RegistryWizardState
Hi, I am running into an issue while configuring EPM system 11.1.2.3. When I enter the Shared Services user credential, it gives me an error "Failed to navigate from RegistryWizardState:. I have granted the shared services user with the following gra