How to set color of a row depending on the value of column in JTable?
Hi All,
I have a JTable that add rows when the user clicks on the button. In this way there can be any no. of rows in my table. My table contains five columns. When a new row is added , it is added with new data each time. Also the data of the rows keep on changing time to time.
My problem is that when the data value for the third column comes out to be -ve then color of the row should be red and if its value is +ve then the color of the row should be green.
I have tried for this in the way but it is not working properly.
public Component prepareRenderer(TableCellRenderer renderer,int rowIndex, int vColIndex)
Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
if(rowIndex<table.getRowCount() && change<0 )
c.setForeground(Color.red);
c.setFont(new Font("TimesRoman",Font.PLAIN,11));
else if(rowIndex<table.getRowCount() && change>0)
c.setForeground(new Color(20,220,20));
c.setFont(new Font("TimesRoman",Font.PLAIN,11));
return c;
where change is the value of the third column.
Any help is highly appreciated.
Thanx in advance.
Regards,
Har Krishan
Perhaps you'll find this link useful. It gives a general idea of how you can create and adjust your custom renderer:
http://www.senun.com/Left/Programming/Java_old/Examples_swing/JTableExamples4.html
Hope it helps.
Eugene
Similar Messages
-
How can I select and delete rows based on the value in one column?
I searched through the discussion board, and found a thread on deleting blank rows, but not sure how to modify it to work with my issue.
I have put together a rather complicated spreadsheet for designing control systems, it calculates parts needed based on check boxes selected in a second spreadsheet.
Since not all systems require all parts there are many rows that have a 0 quantity value, I would like to select these rows and delete them once I have gone through the design phase (checking off required features on a separate sheet).
I like the way the other thread I found will gather all the blank rows at the bottom without changing the order of the rows with data in them.
I don't understand exactly how the formula in the other thread works well enough to modify it to look for a certain column.
I hope I made myself clear enough here, to recap, I would like to sort the rows based on a zero value in one (quantity) column, move them (the zero quantity rows) to the bottom of the sheet, and then delete the rows with a zero quantity (I can delete them manually, but would like to automate the sorting part).
Thanks for any help anyone can provide here.
DannyI apologize but, as far as I know, Numbers wasn't designed by Ian Flemming.
There is no "this column will be auto-destructing after two minutes"
You will have to use your fingers to delete it.
I wish to add a last comment :
if your boss has the bad habit to look over your shoulder, it's time to find an other one.
As I am really pig headed, it's what I did. I became my own boss so nobody looked over my shoulder.
Yvan KOENIG (VALLAURIS, France) mercredi 13 juillet 2011 20:30:25
iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8
Please : Search for questions similar to your own before submitting them to the community
To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer ! -
Getting error while setting color to table rows?
Hi All
I am trying to setting colors to table rows based on dropdown value.
lv_Dropdown vaue =1 i want to set one color, 2-another color like that.
For this I create attribute CELL_DESIGN of type WDUI_TABLE_CELL_DESIGN in node, and i bind this attribute to every column celldesign property in table. and my code in on select of dropdown.
data lr_column type ref to cl_wd_table_column.
data:obj_table type ref to cl_wd_table.
lr_column = obj_table->get_column( id = 'TABLE_WEEK1' ).
if lv_dropdown = 1.
lr_column->set_cell_design(
cl_wd_table_column=>e_cell_design-badvalue_dark ).
endif.
lr_column->bind_cell_design( path = 'SEGMENT1.CELL_DESIGN' ). ...Giving dump at r_colum = get_column( )
I follow correct code or not??
Cheers,
Venkys.Sorry Sarbjeet and baskaran i am not getting,
I want to set colors to row of a table on dropdown selection. In dropdown i ahve a code like
DATA lo_nd_segment1 TYPE REF TO if_wd_context_node.
DATA lo_el_segment1 TYPE REF TO if_wd_context_element.
DATA ls_segment1 TYPE wd_this->Element_segment1.
data lt_segment1 type wd_this->elements_segment1.
DATA lv_segment TYPE wd_this->Element_segment1-segment.
navigate from <CONTEXT> to <SEGMENT1> via lead selection
lo_nd_segment1 = wd_context->get_child_node( name = wd_this->wdctx_segment1 ).
get element via lead selection
lo_el_segment1 = lo_nd_segment1->get_element( ).
lo_el_segment1 = WDEVENT->GET_CONTEXT_ELEMENT( 'CONTEXT_ELEMENT' ).
get all declared attributes
lo_el_segment1->get_static_attributes(
IMPORTING
static_attributes = ls_segment1 ).
DATA : lv_dropdown type string .
lv_dropdown = ls_segment1-segment.
if lv_dropdown = 1. SET ONE COLOR TO THAT ROW
endif.
if lv_dropdown = 2. SET ONE COLOR TO THAT ROW
endif.
Now what should be the code in WDMODIFYVIEW method to set table row with colors.
Cheers,
Venkys. -
How to set colors in cells depending the conditions in alvtree
Hi All,
Could you please provide me idea or sample program how to set colors in cells depending the conditions in alvtree.
Thanks,
SureshWhen running vim in a terminal, it will use whatever colour scheme is defined by the terminal. You should have a look at this thread:
http://bbs.archlinux.org/viewtopic.php?id=51818
Also, check the wiki article on Xdefaults. -
How to set Dropdown list in tablen whith others Dropdown values in each row
how to set Dropdown list in tablen whith others Dropdown values in each row of the table
hi ,
You have to add the parent element before adding data to the child node ...you follow the below steps it will work
1) Take ContextStructure as follows ...
tabledata (valuenode)
ddownbyindex( value node) --within the tabledata node
value (attribute)
2)Binding to your layout
tabledata (node) ---bind this to the dataSource property of your table
ddownbyindex( node)
Value (attribute)--bind to the texts property of you DDbyIndex
3)In wdinit() method add the following code
IPrivate<Your view name>.ITabledataElement tabledataElement =wdContext.createTabledataElement();
wdContext.nodeTabledata().addElement(tabledataElement);
for(int i=0;i<5;i++)
IPrivate<Your viewname>.IDdownbyindexElement ddbyindexElement=wdContext.createDdownbyindexElement();
ddbyindexElement.setValue("Value"+i);
wdContext.nodeDdownbyindex().addElement(ddbyindexElement);
And set the cardinality property of the table node as 0..n
and dropdownbyinex node to 1..n
You try it ...
Regards
Madhavi
Edited by: madhavi kotra on Sep 2, 2008 6:00 PM -
How to set color for a tabstrip in BSP
Hello all,
Can anyone please let me know how to set color for a tabstripn in BSP?
I am using the below syntax but it still gives me the default color.
<htmlb:content design="design2003" >
<htmlb:page title="test " >
<htmlb:form>
<htmlb:tabStrip id = "TabStrip"
bodyHeight = "200"
bodyColor = "red"
width = "700" >
</htmlb:tabStrip>
</htmlb:form>
</htmlb:page>
</htmlb:content>
Thanks,
SandeepHi...
The below code is working fine for me...
<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content design="design2003" >
<htmlb:page title="stg " >
<htmlb:form>
<htmlb:tabStrip width = "430"
bodyColor = "rgb(88,5,64)"
id = "t1"
bodyHeight = "112" >
<htmlb:tabStripItem id = "t1"
index = "1"
title = "Sales"
tooltip = "My Tooltip for Tab 1" >
<htmlb:textView text="Tab N 1" />
<htmlb:tree id = "treeReports"
showTitle = "true"
table2 = "<%= mt_nodes %>"
title = "Menu"
width = "100%" />
</htmlb:tabStripItem>
<htmlb:tabStripItem id = "t2"
index = "2"
title = "Production"
tooltip = "My Tooltip for Tab 2" >
<htmlb:textView text="Tab N 2" />
</htmlb:tabStripItem>
</htmlb:tabStrip>
</htmlb:form>
</htmlb:page>
</htmlb:content> -
How to set focus on next row inputfield in table
Hello all,
How to set focus on next row input field in table
Please help.
Thanks in advance.
CSPHi,
use the following code
wdThis.wdGetAPI().requestFocus(nodeElement, attribute)
Ex:
Provide the attribute and replace the nodeElement with that of yours
IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute("Your attribute");
wdThis.wdGetAPI().requestFocus(wdContext.currentContextElement(), attributeInfo);
Regards
Ayyapparaj -
How to set color space to JPEG image with Java advance Imaging
How to set color space to JPEG image with Java advance Imaging.
is there any API in JAI which support to set color space.I'm definately no guru, but this is how you can change it.
CTRL + ALT + Click on the part of the component that you want to change. This brings up the Hidden Dom Inspector, background of component will be surrounded with a red outline (Make sure the red outline is surrounding the part of the tabset you want to change), Now you go to properties sheet and click the ellipses next to rules property this will pop up a dialog you look in this list (At the top) to see the default style classes that are affecting the rendering of the component outlined in red. (You will be able to select different sections of a single component) then you just rewrite the style class that you want to change in your Stylesheet (You will not find the styleclass that you want to change because it is a part of your theme .jar but as long as you name it exactly the same and place in your stylesheet it will override the theme .jar style classes) it's actually very easy -- you were right should be a piece of cake for a guru. Don't have the link handy but you can check out Winston's Blog on changing Table Formatting to get this information...It is EXTREMELY useful if you want your apps to have a custom look and not default that comes with Creator Themes.
Hope this helps you out God knows others have helped me alot!
Jason -
How to set color to a column in ALV?
Based on standard example BCALV_GRID_01 to modify,
how to set color to a column???
Moderator message: please search for available information/documentation before asking.
Edited by: Thomas Zloch on Nov 6, 2010 9:43 AMHi Sai ,
you are posting the querry in the wrong forum ..
but still I will answer ur querry...
Incase you are not using the standard class to make your ALV then u can set the color of each column in the propertiesof column in the design time .
Incase u see the colors in the design time but is not able to see the colors at the run time then you check the settings of the table I dont have system right now else I could have told you exact property...
else if u r amking alv from the standard class then u will have to search the net for the method to color the same ..
Thanks
Sahil. -
Return specific number of rows depending on the data in a column in table
Hi,
I have a table named orders which has column orderid and noofbookstoorder in addition to other columns.
I want to query the orders table and depending on the value of the 'noofbookstoorder' value return that number of rows.
Eg
Orderid noofbookstoorder
1 1
2 3
3 2
when I query the above data saying
select * from orders where orderid=2;
since it has noofbookstoorders value as 3 the query should return 3 rows and when I query
select * from orders where orderid=3;
it should return 2 rows and
select * from orders where orderid=1;
should return 1 row.
Is it possible to achieve this. If yes, then how do I write my query.
Thanks in advance.with t as (
select 1 Orderid,1 noofbookstoorder from dual union all
select 2,3 from dual union all
select 3,2 from dual
select t.*
from t,
table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
where Orderid = <order-id>
/For example:
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
9 where Orderid = 2
10 /
ORDERID NOOFBOOKSTOORDER
2 3
2 3
2 3
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.OdciNumberList))
9 where Orderid = 3
10 /
ORDERID NOOFBOOKSTOORDER
3 2
3 2
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
iNumberList))
9 where Orderid = 1
10 /
ORDERID NOOFBOOKSTOORDER
1 1
SQL> -- And if you want to select multiple orders
SQL> with t as (
2 select 1 Orderid,1 noofbookstoorder from dual union all
3 select 2,3 from dual union all
4 select 3,2 from dual
5 )
6 select t.*
7 from t,
8 table(cast(multiset(select 1 from dual connect by level <= noofbookstoorder) as sys.Odc
iNumberList))
9 where Orderid in (2,3)
10 /
ORDERID NOOFBOOKSTOORDER
2 3
2 3
2 3
3 2
3 2
SQL> SY.
Edited by: Solomon Yakobson on Oct 26, 2009 7:36 AM -
ColumnChart color depending on the value of the column
Hi,
I'va been trying for 2 days to change the colors of columnseries in a columnchart and it is actually awful. I've tried to do it inline without custom itemRenderer but I quickly understood that it is impossible. I then looked on the internet, and found that it was maybe possible by creating a custom itemRenderer class, extending ProgrammticSkin and implementing IdataRenderer.
I have tried but am not at all able to retrieve the value of the column inside the itemRenderer. Even more, the so called _chartItem is always null and never never carries anything from anyparent.
I'm a bit exhausted of trying and getting this value, so if you have some idea, i'll be very grateful.
Here is the code for my itemRenderer class:
import flash.display.Graphics;
import flash.geom.Rectangle;
import mx.charts.ChartItem;
import mx.charts.chartClasses.GraphicsUtilities;
import mx.charts.series.items.ColumnSeriesItem;
import mx.controls.Alert;
import mx.core.IDataRenderer;
import mx.graphics.IFill;
import mx.graphics.IStroke;
import mx.skins.ProgrammaticSkin;
public class ColorRenderer extends ProgrammaticSkin implements IDataRenderer
public function ColorRenderer():void
super();
private var _chartItem:ChartItem;
public function get data():Object
return _chartItem;
public function set data(value:Object):void {
_chartItem = value as ColumnSeriesItem;
invalidateDisplayList();
private static const fills:Array = [0xFF0000,0x00FF00,0x0000FF,
0x00FFFF,0xFF00FF,0xFFFF00,
0xAAFFAA,0xFFAAAA,0xAAAAFF];
override protected function
updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
var g:Graphics = graphics;
g.clear();
g.beginFill(fills[(_chartItem == null)? 0:_chartItem.element.y]);
Alert.show(_chartItem.index.toString());
g.drawRect(0, 0, unscaledWidth, unscaledHeight);
g.endFill();
} // Close class.
} // Close package.
Thank youIt worked, thanks
Date: Wed, 21 Apr 2010 09:03:14 -0600
From: [email protected]
To: [email protected]
Subject: Flex ColumnChart color depending on the value of the column
Have you looked at doing per-item fills?
http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7c3f.ht ml
This feature lets you define a function that customizes chart item fills based on their values.
> -
How to set up an automatic upper case at the begining of a sentence
Can someone help me if or how to set up an automatic upper case at the beggining of each sentence. I am doing huge amount of writing and just got fed up with it.
What application? Pages? If so, that option (and many others) is not available in the current version. You can use the previous version which should be in your application folder. Or you can do what I finally did and use Open Office or Libre Office.
-
How to split words in two arrays depending of the first letter.
Yes, how to split words in two arrays depending of the first letter.
I have a string array with some words, and I need to separe this array into two differents string arrays depending of the first letter:
if the word starts in A to M the word goes to array Words_AM;
if the word starts in N to Z the word goes to array Words_NZ;
Now I'm doing the next:
if ((ArrayWord.charAt(0))<='a') && (ArrayWord.charAt(0)>='m')) {
Words_AM]=ArrayWord;
else
Words_NZ[i]]=ArrayWord;
But doesn't work.
Any solution?
Best wishes.Yes , that's true. But also I have to change the <='a' to <'a', because of with first option didn't selecting the a letter.
But with z letter, doing the same before, doens't run.
if ((ArrayWord.charAt(0))<'a') || (ArrayWord.charAt(0)>='m'))
Words_NZ]=ArrayWord;
else
if ((ArrayWord.charAt(0))<='n') || (ArrayWord.charAt(0)>'z')) Words_AM[i]]=ArrayWord;
Regards ;) -
Shading part of a JTable Cell dependent upon the value of the cell
Hi
Was hoping some one woudl be able to provide some help with this. I'm trying to create a renderer that will "shade" part of a JTable cell's background depending upon the value in the cell as a percentage (E.g. if the cell contains 0.25 then a quarter of the cell background will be shaded)
What I've got so far is a renderer which will draw a rectangle whose width is the relevant percentage of the cell's width. (i.e. the width of the column) based on something similar I found in the forum but the part I'm struggling with is getting it to draw this rectangle in any cell other than the first cell. I've tried using .getCellRect(...) to get the x and y position of the cell to draw the rectangle but I still can't make it work.
The code for my renderer as it stands is:
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
public class PercentageRepresentationRenderer extends JLabel implements TableCellRenderer{
double percentageValue;
double rectWidth;
double rectHeight;
JTable table;
int row;
int column;
int x;
int y;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value instanceof Number)
this.table = table;
this.row = row;
this.column = column;
Number numValue = (Number)value;
percentageValue = numValue.doubleValue();
rectHeight = table.getRowHeight(row);
rectWidth = percentageValue * table.getColumnModel().getColumn(column).getWidth();
return this;
public void paintComponent(Graphics g) {
x = table.getCellRect(row, column, false).x;
y = table.getCellRect(row, column, false).y;
setOpaque(false);
Graphics2D g2d = (Graphics2D)g;
g2d.fillRect(x,y, new Double(rectWidth).intValue(), new Double(rectHeight).intValue());
super.paintComponent(g);
}and the following code produces a runnable example:
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class PercentageTestTable extends JFrame {
public PercentageTestTable()
Object[] columnNames = new Object[]{"A","B"};
Object[][] tableData = new Object[][]{{0.25,0.5},{0.75,1.0}};
DefaultTableModel testModel = new DefaultTableModel(tableData,columnNames);
JTable test = new JTable(testModel);
test.setDefaultRenderer(Object.class, new PercentageRepresentationRenderer());
JScrollPane scroll = new JScrollPane();
scroll.getViewport().add(test);
add(scroll);
public static void main(String[] args)
PercentageTestTable testTable = new PercentageTestTable();
testTable.pack();
testTable.setVisible(true);
testTable.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}If anyone could help or point me in the right direction, I'd appreciate it.
RuanaeThis is an example I published some while ago -
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class Fred120 extends JPanel
static final Object[][] tableData =
{1, new Double(10.0)},
{2, new Double(20.0)},
{3, new Double(50.0)},
{4, new Double(10.0)},
{5, new Double(95.0)},
{6, new Double(60.0)},
static final Object[] headers =
"One",
"Two",
public Fred120() throws Exception
super(new BorderLayout());
final DefaultTableModel model = new DefaultTableModel(tableData, headers);
final JTable table = new JTable(model);
table.getColumnModel().getColumn(1).setCellRenderer( new LocalCellRenderer(120.0));
add(table);
add(table.getTableHeader(), BorderLayout.NORTH);
public class LocalCellRenderer extends DefaultTableCellRenderer
private double v = 0.0;
private double maxV;
private final JPanel renderer = new JPanel(new GridLayout(1,0))
public void paintComponent(Graphics g)
super.paintComponent(g);
g.setColor(Color.CYAN);
int w = (int)(getWidth() * v / maxV + 0.5);
int h = getHeight();
g.fillRect(0, 0, w, h);
g.drawRect(0, 0, w, h);
private LocalCellRenderer(double maxV)
this.maxV = maxV;
renderer.add(this);
renderer.setOpaque(true);
renderer.setBackground(Color.YELLOW);
renderer.setBorder(null);
setOpaque(false);
setHorizontalAlignment(JLabel.CENTER);
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
final JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
if (value instanceof Double)
v = ((Double)value).doubleValue();
return renderer;
public static void main(String[] args) throws Exception
final JFrame frame = new JFrame("Fred120");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new Fred120());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} -
Variant network depending on the value of the characteristics.
Hi,
I want to create a project from a sales order for a configurable material. The problem is that the network should be slightly different depending on the value of the characteristics used in the configurable material. For example, it could happen that one operation should not be executed, or that this operation should take longer because of the characteristics.
How should I proceed?
Thanks in advance.
Regards,
Luis.Thanks for your answers, but I needed a more specific answer. Anyway, in the end I found the solution:
- I had to create a configuration profile for the standard network (CU41), and then I had to assign the same class as the one assigned to the configuration profile of the configurable material.
- Then, I run t-code CN02, and I had to select one operation and then I clicked "Extras --> Object Dependencies --> Editor". And finally, I just chose the dependency type and filled it with its corresponding code.
Still, I have a problem:
- Is it possible to set the value of the Normal Duration (or any other parameter of the operation) depending on the value of one characteristic?
For example: The value of my characteristic A is 2, so I want to set Normal Duration = 10*(Value_of_A) = 20 for the first operation of the standard network. Is it possible in standard SAP???
Thanks!
Maybe you are looking for
-
ello when i try to down load itunes if says "This installation package can not be opened. Verify that the package exist and that can access it. or contact provider" what do i do LOST
-
Greetings, I have implemented the ISSOIntegration interface, and in the GetSecureCookies method I am returning an array of cookie names that I want passed down to my portlets. I hit the portal with the said cookies in the headers, and I am able to ex
-
I received the following email to reactivate my account. Is this real or is it spam??? Welcome to iTunes Services. Dear Customer, Apple takes the security of our customers personal and account information very seriously. As part of our ongoing effort
-
Aborting a subvi and then returning back into the subvi
Anyone, I have a subvi that is gathering calibration values in a while loop. However, this subvi gathers precal data before the actual calibration data in which this precal gathering process takes quite a bit of time. When I run this subvi by itsel
-
Small question related to Unix and ABAP
Hi Guys, I had a new SAP ABAP requirment in which they are asking for unix shell scripting. I am just wondering as what unix shell scripting has to do in SAP ? Please throw some light on this.... Regards, Tushar.