JTable Cells with different Color according to value
Pls help I want to be able to display all rows (students) that paid more than 20 naira in Green
else display rows (student) that paid < 20 naira in red
But at the moment it is displaying everything in green why?
tmp is the variable
Code would help pls!
class TestRenderer extends DefaultTableCellRenderer
public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row, int column)
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (row > 0)
for (int i =0; i < table.getRowCount(); i++)
String tmpString = (String) table.getValueAt(i,3);
if (tmpString != null)
double tmp = Double.parseDouble(tmpString);
if (tmp > 20)
System.out.println("Variable is "+tmp);
setBackground( Color.green );
else
setBackground( Color.red );
return this;
Get rid of that loop
String tmpString = (String) table.getValueAt(row,3);
Similar Messages
-
How to color single column cells with different colors in classic report based different conditions
Hi ,
Am working on Oracle Apex 4.2 version. Am trying to generate a classic report with different cell colors based on the conditions.
I tried the solution provided in the below link.
https://forums.oracle.com/message/9518723#9518723.
I tried the same query given in that link.
SELECT e.*,
CASE
WHEN sal < 1000
THEN 'red'
WHEN sal BETWEEN 1000 AND 2000
THEN 'yellow'
WHEN sal > 2000
THEN 'green'
END the_color
FROM emp e
And, I hidded the column 'the_color' in Report Attributes,
the Column Template1 has the code , <td #ALIGNMENT# headers="#COLUMN_HEADER_NAME#">#COLUMN_VALUE#</td>.
After this, what are the steps did I miss here. Because am not getting the report which I need.
Kindly do provide solution.
Thanks,
yashu.SAL column values should visible with different color based on the conditions. Same way i did in my report it was working for me. Please refer the below links for more information,
https://forums.oracle.com/thread/1047891
http://dbswh.webhop.net/htmldb/f?p=BLOG:READ:0::::ARTICLE:351800346145832
Thanks
Lakshmi -
Display of text of different rows with different color - JTable
Hi all !
I have struck in a problem. I have to display the different rows with different color in the JTable. I have created an arraylist in the model class, which stores color of all the rows. Now in renderer class, I am just picking up color from the arraylist, taking rowIndex as index for arraylist. I used to set foreground color for each row in the renderer class. The problem is that it is not showing all the rows properly, sometimes it show all the rows correctly, but as i resize the window/panel, it starts behaving abnormally, some text is painted properly, but other aren't.
Does anybody have any solution regarding this problem.
One thing i want to mention is that in getTableCellRendererComponent() method, i used to retrive the color everytime, and setting the foreground color of the text. Is this a right approach or some other technique have to be followed.
here is code of renderer class ---
import java.awt.*;
import javax.swing.*;
* Renderer to plot stage record table.
public class ExStageCellRenderer extends javax.swing.table.DefaultTableCellRenderer
Color curColor;
* returns component to be painted, overridding this method from
* DefaultCellRenderer
* @param table
* table whose component has to be plotted
* @param value
* value of that particular cell
* @param isSelected
* is Cell selected
* @param hasFocus
* has the cell got focus
* @param row
* row of the cell
* @param column
* column of the cell
* @return painted component
public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
int column)
Component component = super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column);
ExStageDataModel model = (ExStageDataModel)table.getModel ();
if (curColor instanceof Color) {
curColor = model.getColor(row);
} else {
// If color unknown, use table's foreground color
curColor = table.getForeground();
String tooltip = "";
StringBuffer stringBuffer = new StringBuffer ();
for (int i = 0; i < table.getColumnCount (); i++)
Object Value = table.getValueAt (row, i);
if (Value == null) continue;
stringBuffer.append (Value.toString () + " ");
tooltip += stringBuffer.toString ();
tooltip = tooltip.trim ();
((JComponent) component).setToolTipText (tooltip);
if (column == 1)
this.setHorizontalAlignment (SwingConstants.CENTER);
else if (column == 0 || column == 4 || column == 5)
this.setHorizontalAlignment (SwingConstants.LEFT);
else
this.setHorizontalAlignment (SwingConstants.RIGHT);
// LOOK!! should turn tip off if there is none !!
component.setForeground (this.curColor);
//System.out.println("render : " + component.getBounds ());
//component.validate ();
component.update (component.getGraphics ());
return component;
Waiting for reply....
Code snookerHmm, why are you doing the curColor instanceof? What does this accomplish? I don't see any reason to ask what it was before; all you should be interested in here is what you want it to be now.
All you should have to do is say:
this.setForeground(model.getColor(row));I also don't see why you're doing the update() -- JTable is going to do that for you at the appropriate time, you have no idea if now is the right time to do it or not. In fact it probably isn't, you're probably updating the previously-drawn cell with your new color and alignment, which may be the strange behavior you're seeing.
Also, I don't see why you're doing the super. All that's going to do is return "this", so why not just use "this"?
Well, without knowing your larger code or exactly what you're trying to accomplish, maybe I'm just missing something.
I've just recently been working on a program where I had some similar requirements -- different foreground and background colors and alignment -- and I found it much cleaner to create a class to hold all this data, and then create a default renderer for that class. Then I made some constructors for this "attribute" class that let me set whatever I need, like
public CellAttrib(String s,Color c,int alignment,Border border)
this.s=s;
this.c=c;
this.border=border;
// with suitable defaults ...
pubic CellAtrtrib(String s)
this.s=s;
this.c=Color.BLACK;
this.border=null;
}Then the renderer just queried the cell-attributes class, as in:
setForeground(value.getColor());
setHorizontalAlignment(value.getAlignment());
setBorder(value.getBorder); -
JTable cell with colored string
Hi,
How can I make colored string in cell (string with different colors) ?Supposing you haven't used your own customized cell renderers, the following code must work..
((DefaultTableCellRenderer)<<yourtable>>.getCellRenderer(<row>, <col>)).setForeground(Color.BLUE);
This will paint all the cells of same type as cell(<row>, <col>) in blue.
If you want only certain cells in your table to be painted in a perticular colour, you may have to write a customized renderer yourself, extending the javax.swing.table.DefaultTableCellRenderer class, and override its getTableCellRendererComponent(...) method as per your required functionality. -
Not able to color different rows with different colors in a column of table
Hi,
I am trying to to display different rows with different colors in a column of the table based on some decode condition.
I have gone through the following threads :
Can we colour the rows in the column of a table
Changing Color of a value in a column
This is what i have done :
1.Added the following code to custom.xss(changed the name to Custom.xss as suggested in one of the above threads) --- in path ---- jdev\myhtml\OA_HTML\cabo\styles
<style selector=".1">
<includeStyle name="DefaultFontFamily"/>
<property name="font-size">11pt</property>
<property name="font-weight">Bolder</property>
<property name="color">#008000</property>
<property name="text-indent">3px</property>
</style>
<style selector=".2">
<includeStyle name="DefaultFontFamily"/>
<property name="font-size">11pt</property>
<property name="font-weight">Bolder</property>
<property name="color">#FFFF00</property>
<property name="text-indent">3px</property>
</style>
2. Sql query of the VO is :
select comments,role ,decode(role,'REQUESTER','1','2') Colorattr from xxat_sars_action_history where request_id = :1 and event_name = :2 and action_code <> 'PENDING'
order by sequence_num desc
3. Coded the following in the process request of the controller:
OATableBean table = (OATableBean)webBean.findIndexedChildRecursive("CommentsTB");
OAMessageStyledTextBean roleBN = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("role");
OADataBoundValueViewObject cssjob = new OADataBoundValueViewObject(roleBN,"Colorattr");
roleBN.setAttributeValue(oracle.cabo.ui.UIConstants.STYLE_CLASS_ATTR, cssjob);
where 1 and 2 form the colors ( i have even tried with 'Red' and 'Yellow'...as it was not working replaced with 1 and 2)
4.The query returns data fine with corresponding 1 and 2 values.
But different colors are not getting reflecting on to the UI.
I am testing this on my local jdev.
Please do let me know if i am missing something.
Thanks ,
Sushma.Any Clues please.....
Thanks,
Sushma. -
XY Graph overlay multi plot with different colors
Hi,
I want to do a cyclic X-Y plot in a for loop and plot the graph for each cycle in different colors.
I want a plot like XYgraph2 but with different colors and probably even without that tracing line. How do i modify my diagram?
Thank you for your time and efforts.
SUCHIT
Suchit Shah
Graduate Student
Electrical & Computer Engineering,
Northeastern University,
BOSTON
MA 02115
Certified LabVIEW Associate Developer
Solved!
Go to Solution.
Attachments:
block dia.JPG 45 KB
front dia.JPG 122 KBHi all! This is my first post
My name is Francesco and I'm programming a keithley for measure some FET
using labview 8.6. I plot my output data on a XY graph but I have several curves,
one for each value of Vgs. Looking in your forum I've found the code
MultiplePlots.vi (21 kb) posted by Darin.K about a month ago that use Multiple
plots and it is perfect for my goal because with this I can plot every curve with a
different color. The only problem is that I like to plot my data in real time.
The code, however, use a Loop with N=50, accumulates the values on the edge
and plot at the end of the Loop the entire line.
My question is if someone can explain me how to modify the code to plot the line
point by point, so in real time and not at the end o the loop because I need to see
the current values during the measurement and not only at the end.
I think that I need to move the XYgraph inside the loop. I try but without lucky.
Can anyone help me?
thanks and sorry for my very bad english.
Francesco -
Cracked iPhone 6 screen and screen is all white with different colors going down it. What do I do???
Take it in for repair or exchange. Be prepared to write a pretty big check unless you bought AppleCare+.
If your iPod Touch, iPhone, or iPad is Broken
Apple does not fix iDevices. Instead, they exchange yours for a refurbished or new replacement depending upon the age of your device and refurbished inventories. On rare occasions when there are no longer refurbished units for your older model, they may replace it with the next newer model.
ATTN: Beginning July 2013 Apple Stores are now equipped to do screen repairs/replacements in-house on iPhone 5 and 5C. In some cases while you wait. According to Apple this is the beginning of equipping Apple Stores with the resources needed to do most repairs for iPhones, iPads, and iPod Touches that would not require major replacements. Later in the year the services may be extended as Apple Stores become equipped and staffed with the proper repair expertise. So, if you need a screen repaired or a broken screen replaced or have your stuck Home button fixed, call your local Apple Store to see if they are now doing these in-house.
You may take your device to an Apple retailer for help or you may call Customer Service and arrange to send your device to Apple:
Apple Store Customer Service at 1-800-676-2775 or visit online Help for more information.
To contact product and tech support: Contacting Apple for support and service - this includes international calling numbers.
You will find respective repair costs in the appropriate link:
iPod Service Support and Costs
iPhone Service Support and Costs
iPad Service Support and Costs
There are third-party firms that do repairs on iDevices, and there are places where you can order parts to DIY if you feel up to the task:
1. iResq or Google for others.
2. Buy and replace screen yourself: iFixit -
Creating Cells with differing heights in Numbers '09
In any given Row is it possible to have different cells with different heights because I've found that if I set the cell height to be e.g. 1cm then all the cells in the whole row are 1cm which isn't always the desired effect.
ThanksS,
A Row is a unit with a singular height value. All cells in that row will have the same height in a Numbers Table. Adjacent rows can be made to appear to have cells with differing heights by manipulating the Cell Border characteristics. You also have the option to combine individual tables in such a way that they appear to be a single table with different row heights.
Jerry -
Plot a bar graph of 1D array with different color of each bar?
Any one has example for a graph of 1 D array ( exp: [1,2,6,4,6] with different color of each bar? I want to make a bar graph of 1 D array, exp :if the value >=5, the bar is red, value< 5 is blue.
What's wrong with the solution I showed you over two weeks ago?
http://forums.ni.com/ni/board/message?board.id=170&view=by_date_ascending&message.id=281455#M281455
LabVIEW Champion . Do more with less code and in less time . -
Running Border Animation with different colors ?
Hey..Any body can help me to create a animation of dashed lines with different colors ??i mean border like LEd lyts around the fotos of God ??
Hi,
If you set the style properties for the Panel you want to
modify, it will consider the properties you set than loading from
the global css file. I have created a sample in which i have two
Accordions, in which one Accordion uses the global style for the
header and other one uses the style which i set for that Accordion.
Hope this helps -
On a chart, can we set portions of a chart with different colors
My application involves with fuel cell conditioning during which the V-I curve with go many cycles. I want to distinguish these cycles with different colors but don't know whether it's doable because I think if we set a color, it will set the whole line with the same color. Or if we can stop the line after one cycle and start the second cycle as a new line, then it will be a new color. Anyone can give some suggestion about how it can work? Thanks in advance.
GuangdeBy bundling multiple points together you can get different plots on a waveform graph. And +Inf plots nothing. I attached an example that plots a random number. When the boolean button is switched, it switches to the other plot line, thus another color. This was only done for 2 different colors, but the case structure and the cluster could be expanded for more than 2 colors.
Message Edited by Ravens Fan on 08-24-2007 10:43 PM
Attachments:
Untitled 1.vi 14 KB
Example_BD.png 12 KB -
Numbers point to a cell with different formatting to create conditional format
Hi all, not sure if this has been brought up but my search efforts haven't found anything. I know conditional formatting is not supported in IOS numbers but I saw a buddy do a little trick a while ago and I've been trying to replicate it. On his iPad, he created a numbers spreadsheet that had a logic function (=if). And if that function was true it pointed to another cell with different formatting. The result was, the cell would become the same format as the cell it was pointing too. This created the effect of a conditional format in a sense. I can get this to work with limited effect, only if the cell is a "text" cell and not a formula. As well the background colour doesn't get picked up, only the format of the cell text itself. I'm trying to get in touch with him for help but in the mean time does anyone have any experience in this kind of method?
CheersAs an example:
If A > B, then A-B, otherwise make it equal this other cell (D1 for example)
{=if(a1>b1,a1-b1,d1)}
And in that d1 cell I would make another formula that also does the same subtraction (a1-b1) however knowing it will be a negative number this time, I paint the cell bright red and hopefully the original cell will then look the same since it is now equal to this one.
Unfortunately it looks like this wont work. The closest thing to doing this trick I have found is pointing to a cell formatted as text, such as a blank cell. Then the original cell takes on the formatting characteristics of the text cell. The problem is the text cell is useless since it can't do any sort of math. I can't even set the cell to simply equal another one and format it as text only. So far it looks like the only conditional type of trickery I can do is make the numbers disappear by pointing to a blank text cell.
I hope that helps describe it a little better. -
IPad 2 Built-in Calendar App - Adding new calanders with different colors
I have an iPad 2, i've read the user guide and still can not figure out how to add a new calendar in the 'built-in app'. I want to separate my events with different colors it is shown like that in the user guide, but it doesn't explain how to do it.
Do you have a Google, Exchange or MobileMe email account? If you have one of those accounts, I think you can add them in the Mail settings.
I Googled this and you can look through it and see what you can find.
http://www.google.com/search?q=add+calendars+to+iPad&ie=utf-8&oe=utf-8&aq=t&rls= org.mozilla:en-US:official&client=firefox-a
Other than my Exchange calendar, all of my other calendars were set up on my Mac with iCal. I copied this from this support article ...
http://support.apple.com/kb/ht1296
Calendars
To sync calendars with your computer, choose "Sync Calendars" or "Sync iCal Calendars."
You can sync calendars with:
Microsoft Outlook 2003, Microsoft Outlook 2007, Microsoft 2010 (Windows XP, Windows Vista, or Windows 7)
iCal (Mac OS X)
Microsoft Entourage 2004, Microsoft Entourage 2008
Note: If using Microsoft Entourage, use Microsoft Entourage 2008 12.1.2 or later if syncing with Mac OS X v10.6 or later. If you would like to sync data on your Mac with Entourage, enable syncing between Entourage and Address Book.
Microsoft Outlook 2011 for Mac
Note: If using Microsoft Outlook 2011 for Mac to sync calendars you must update to Microsoft Office 2011 for Mac Service Pack 1 or later.
Notes:
When syncing calendars, you can sync all calendars or sync specific calendars.
You can limit the data that is synced to only events that have occurred in the last 30 days. The option can be changed to any number of days. -
Unable to use two af:tables with differing coloring (skins)?
Im trying to configure the Siebel Self-Services application and customize the skinning. I have some problems though, because i need to show two af:tables on the same page, but with different coloring. One with black background and white text (both header and body) and one with white background and black text. I have tried to use styleClass:es, but the css parameters set for the af table are overriding the ones set in the stylesheets.
Anyone having an idea how to overcome this?
Thanks
/Jon-ErikHi,
if the styleClass name is table1 then the skin selector would be something like
.table1 af|table
or .afTable.af|table
I don't see how this can be overriden. If you assumption is that the style class reference must be to a CSS definition on the page then this indeed does not work. The styleClass name is kind of a named identifier for the component to skin and is used to further qualify the component to skin
Frank -
IPad 1 display with different color line
My iPad display shows with different colors here & there. Is that defect? Some web page is ok. But most of time you can see that.
Mountpa-
Your iPad may be defective, but is probably out of warranty. An Apple Store may exchange it for a flat rate. Look for an iPad repair center for a less expensive repair. You can find an Apple Authorized Repair Center at <Apple Authorized Repair Centers>, but non-Apple repair centers may be less expensive still.
First check to see if your color happens to be part of your iPad's wallpaper. Go to Settings-Brightness & Wallpaper to see how it is currently set.
One thing you can try is to reset (reboot) your iPad. Hold both the Home and Sleep buttons for several seconds until the Apple logo appears. Ignore the "Slide to power off" arrow. The iPad will restart after a couple of minutes. Resetting this way will not hurt anything, and sometimes clears up mysterious problems.
Fred
Maybe you are looking for
-
Photoshop cannot open EM5 II RAW files even with 8.8 ACR?!
I have an active Adobe CC subscription so my Photoshop is already the latest version, but when I try to open EM5 II .ORF files, I get message "Photoshop cannot open this file." (see attached screenshot) EM5 II is already officially supported accordin
-
Why is the rubber part on the bottom of my computer separating from the computer? It looks like a screw is missing? Is this typical? I bought it last March.
-
How do I submit my photo for my podcast page?
I already submitted my podcast and it was accepted by iTunes. At the time, I didn't have a photo to put up so I skipped that part (thinking I could do it later). Now I can't figure out how to get an image up, and it's all ready (600x600 px). I also d
-
Why doesn't Bridge Recognize Canon G1X Raw Images even with ACR 6.6?
I got a new Canon G1X and upgraded my Adobe Camera Raw to version 6.6 which is supposed to recognize this camera. No matter what I do, the bridge thumbnail never appears and I cannot open the files on Photoshop. I always get an error message that th
-
Where is the DefaultRealmImpl class?
Hello all, I have been getting the java.lang.ClassNotFoundException: weblogic.security.acl.DefaultRealmImpl. I have been looking around for the class in order to add it to my classpath, but I have not been able to locate it. Does anyone know where, e