Setting selection in table by code
Hi,
I'm trying to set the selction interval in code using setSelectionInterval(x, x) on a JTable ListSelectionModel without success. Nothing gets selected.
Any ideas?
Not really any suggestions... the following code works for me:
final JFrame test_frame = new JFrame("Test");
test_frame.getContentPane().setLayout(new BoxLayout(test_frame.getContentPane(), BoxLayout.Y_AXIS));
JPanel panel = new JPanel(new SpongyLayout(SpongyLayout.Orientation.HORIZONTAL, false));
test_frame.getContentPane().add(panel);
final JTable table = new JTable(new Object[][]{new Object[]{"A", "B"},
new Object[]{"C","D"},
new Object[]{"E","F"},
new Object[]{"G","H"}}, new Object[]{"1","2"});
table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
panel.add(new JScrollPane(table));
JButton b = new JButton("Select 1 & 2");
panel.add(b);
b.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
table.getSelectionModel().setSelectionInterval(1,2);
b = new JButton("Select 0, 2 & 3");
panel.add(b);
b.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
table.getSelectionModel().setSelectionInterval(0,0);
table.getSelectionModel().addSelectionInterval(2,3);
b = new JButton("Deselect");
panel.add(b);
b.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
table.getSelectionModel().removeSelectionInterval(0,3);
test_frame.pack();
test_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AWTUtilities.centerWindow(test_frame, null);
test_frame.setVisible(true);We'll need more information on exactly what you're doing which is unusual enough to break the API. :)
Similar Messages
-
hello,
I have a question, you know if you show a list or a table on te screen , you can select an item by clicking on it, you actualy see what you selected because it turns blue (background). What i would like to do is the same but from my code, i select something from code , and the user can see it because it turns bleu
Greetz
dsnicoHi,
I'm not sure, but it looks like you can set the selection model of the JTable to be a ListSelectionModel which supports a setSelectionInterval(int index0, int index1) interface. Setting the interval may select those rows/cells in the gui.
Daniel Roth -
Help to set selected row in adf table!
Hello,
I have a problem with adf table, when I select one row in table, I want to set selecte to next row or first row , or end row . . .
How can I do that.
If anyone know it, please help me
Thanks in advance.<af:table value="#{bindings.BuddyView1.collectionModel}" var="row" partialTriggers="id"
rows="#{bindings.BuddyView1.rangeSize}"
emptyText="#{bindings.BuddyView1.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.BuddyView1.rangeSize}"
rowBandingInterval="0"
selectedRowKeys="#{bindings.BuddyView1.collectionModel.selectedRow}"
*selectionListener="#{bindings.BuddyView1.collectionModel.makeCurrent}"*
rowSelection="single" binding="#{backing_untitled1.t1}"
id="t1">
You will have to create your own selection listener method.
Cheers
Venkat
Edited by: Venkat81 on Jun 10, 2010 11:12 AM -
JTree custom renderer setting selection background color problem
Hi,
I have a JTree with a custom icon renderer that displays an icon. The JTree is part of a TreeTable component. Iam having a problem setting the selection background uniformly for the entire row. There is no problem when there is no row selected in the JTable.
My present code looks like this:
Iam overriding paint in my renderer which extends DefaultCellRenderer.
super.paint(g);
Color bColor = null;
if(!m_selected) {
if(currRow % 2 == 0) {
bColor = Color.WHITE;
} else {
bColor = backColor;
} else {
bColor = table.getSelectionBackground(); bColor = getRowSelectionColor();
if(bColor != null) {
g.setColor(bColor);
if(!m_selected) {
g.setXORMode(new Color(0xFF, 0xFF, 0xFF));
} else {
g.setXORMode(new Color(0x00, 0x00, 0x00));
I have a color I arrive at using some algorithm that I want using method getRowSelectionColor(). The other cells in the row have this color. But the cell containing the tree node shows different color. Iam not able to arrive at the right combination of the color to set and the xor color so my tree node also looks like the other cells in the row.
It is not a problem really as the table still looks good. Its just that the tree node looks like it has been highlighted and this might cause a problem when a table cell is highlighed later on in the application ( two cells in the row would be highlighted causing confusion).
Any help would be appreciated.
Regards,
vidyutHi Camickr,
Thanks for the reply. Iam sorry I didn't include the sources the first time around. There were too many of them. I have created a small, self-contained, compilable program that demonstrates the problem and including it herewith. Still there's quite many files but they are all needed Iam afraid. The only one you will have to concern yourself fior this problem is the file IconRenderer.java. The treenode background and the other cells background are not in sync when table row is not selected in this example though. But they are in my real program. I just need them to be in sync i.e have the same background color when the row is selected.
Your help would be very much appreciated.
These are the files that are included below:
1. AbstractTreeTableModel.java
2. Bookmarks.java
3. BookmarksModel.java
4. DynamicTreeTableModel.java
5. IconRenderer.java
6. IndicatorRenderer.java
7. JTreeTable.java
8. TreeTableExample3.java (contains main)
9. TreeTableModel.java
10. TreeTableModelAdapter.java
The copyright and javadocs information has been stripped for clarity.
cheers,
vidyut
// AbstractTreeTableModel.java BEGIN
import javax.swing.tree.*;
import javax.swing.event.*;
public abstract class AbstractTreeTableModel implements TreeTableModel {
protected Object root;
protected EventListenerList listenerList = new EventListenerList();
public AbstractTreeTableModel(Object root) {
this.root = root;
// Default implementations for methods in the TreeModel interface.
public Object getRoot() {
return root;
public boolean isLeaf(Object node) {
return getChildCount(node) == 0;
public void valueForPathChanged(TreePath path, Object newValue) {}
// This is not called in the JTree's default mode:
// use a naive implementation.
public int getIndexOfChild(Object parent, Object child) {
for (int i = 0; i < getChildCount(parent); i++) {
if (getChild(parent, i).equals(child)) {
return i;
return -1;
public void addTreeModelListener(TreeModelListener l) {
listenerList.add(TreeModelListener.class, l);
public void removeTreeModelListener(TreeModelListener l) {
listenerList.remove(TreeModelListener.class, l);
protected void fireTreeNodesChanged(Object source, Object[] path,
int[] childIndices,
Object[] children) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeModelEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners==TreeModelListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeModelEvent(source, path,
childIndices, children);
((TreeModelListener)listeners[i+1]).treeNodesChanged(e);
protected void fireTreeNodesInserted(Object source, Object[] path,
int[] childIndices,
Object[] children) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeModelEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeModelListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeModelEvent(source, path,
childIndices, children);
((TreeModelListener)listeners[i+1]).treeNodesInserted(e);
protected void fireTreeNodesRemoved(Object source, Object[] path,
int[] childIndices,
Object[] children) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeModelEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeModelListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeModelEvent(source, path,
childIndices, children);
((TreeModelListener)listeners[i+1]).treeNodesRemoved(e);
protected void fireTreeStructureChanged(Object source, Object[] path,
int[] childIndices,
Object[] children) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeModelEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeModelListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeModelEvent(source, path,
childIndices, children);
((TreeModelListener)listeners[i+1]).treeStructureChanged(e);
// Default impelmentations for methods in the TreeTableModel interface.
public Class getColumnClass(int column) { return Object.class; }
public boolean isCellEditable(Object node, int column) {
return getColumnClass(column) == TreeTableModel.class;
public void setValueAt(Object aValue, Object node, int column) {}
// Left to be implemented in the subclass:
* public Object getChild(Object parent, int index)
* public int getChildCount(Object parent)
* public int getColumnCount()
* public String getColumnName(Object node, int column)
* public Object getValueAt(Object node, int column)
// AbstractTreeTableModel.java END
// Bookmarks.java BEGIN
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.text.html.parser.*;
public class Bookmarks {
/** The root node the bookmarks are added to. */
private BookmarkDirectory root;
* Creates a new Bookmarks object, with the entries coming from
* <code>path</code>.
public Bookmarks(String path) {
root = new BookmarkDirectory("Bookmarks");
if (path != null) {
parse(path);
* Returns the root of the bookmarks.
public BookmarkDirectory getRoot() {
return root;
protected void parse(String path) {
try {
BufferedReader reader = new BufferedReader(new FileReader
(path));
new ParserDelegator().parse(reader, new CallbackHandler(), true);
catch (IOException ioe) {
System.out.println("IOE: " + ioe);
JOptionPane.showMessageDialog(null, "Load Bookmarks",
"Unable to load bookmarks",
JOptionPane.ERROR_MESSAGE);
private static final short NO_ENTRY = 0;
private static final short BOOKMARK_ENTRY = 2;
private static final short DIRECTORY_ENTRY = 3;
private class CallbackHandler extends HTMLEditorKit.ParserCallback {
/** Parent node that new entries are added to. */
private BookmarkDirectory parent;
/** The most recently parsed tag. */
private HTML.Tag tag;
/** The last tag encountered. */
private HTML.Tag lastTag;
* The state, will be one of NO_ENTRY, DIRECTORY_ENTRY,
* or BOOKMARK_ENTRY.
private short state;
* Date for the next BookmarkDirectory node.
private Date parentDate;
* The values from the attributes are placed in here. When the
* text is encountered this is added to the node hierarchy and a
* new instance is created.
private BookmarkEntry lastBookmark;
* Creates the CallbackHandler.
public CallbackHandler() {
parent = root;
lastBookmark = new BookmarkEntry();
// HTMLEditorKit.ParserCallback methods
* Invoked when text in the html document is encountered. Based on
* the current state, this will either: do nothing
* (state == NO_ENTRY),
* create a new BookmarkEntry (state == BOOKMARK_ENTRY) or
* create a new
* BookmarkDirectory (state == DIRECTORY_ENTRY). If state is
* != NO_ENTRY, it is reset to NO_ENTRY after this is
* invoked.
public void handleText(char[] data, int pos) {
switch (state) {
case NO_ENTRY:
break;
case BOOKMARK_ENTRY:
// URL.
lastBookmark.setName(new String(data));
parent.add(lastBookmark);
lastBookmark = new BookmarkEntry();
break;
case DIRECTORY_ENTRY:
// directory.
BookmarkDirectory newParent = new
BookmarkDirectory(new String(data));
newParent.setCreated(parentDate);
parent.add(newParent);
parent = newParent;
break;
default:
break;
state = NO_ENTRY;
* Invoked when a start tag is encountered. Based on the tag
* this may update the BookmarkEntry and state, or update the
* parentDate.
public void handleStartTag(HTML.Tag t, MutableAttributeSet a,
int pos) {
lastTag = tag;
tag = t;
if (t == HTML.Tag.A && lastTag == HTML.Tag.DT) {
long lDate;
// URL
URL url;
try {
url = new URL((String)a.getAttribute(HTML.Attribute.HREF));
} catch (MalformedURLException murle) {
url = null;
lastBookmark.setLocation(url);
// created
Date date;
try {
lDate = Long.parseLong((String)a.getAttribute("add_date"));
if (lDate != 0l) {
date = new Date(1000l * lDate);
else {
date = null;
} catch (Exception ex) {
date = null;
lastBookmark.setCreated(date);
// last visited
try {
lDate = Long.parseLong((String)a.
getAttribute("last_visit"));
if (lDate != 0l) {
date = new Date(1000l * lDate);
else {
date = null;
} catch (Exception ex) {
date = null;
lastBookmark.setLastVisited(date);
state = BOOKMARK_ENTRY;
else if (t == HTML.Tag.H3 && lastTag == HTML.Tag.DT) {
// new node.
try {
parentDate = new Date(1000l * Long.parseLong((String)a.
getAttribute("add_date")));
} catch (Exception ex) {
parentDate = null;
state = DIRECTORY_ENTRY;
* Invoked when the end of a tag is encountered. If the tag is
* a DL, this will set the node that parents are added to the current
* nodes parent.
public void handleEndTag(HTML.Tag t, int pos) {
if (t == HTML.Tag.DL && parent != null) {
parent = (BookmarkDirectory)parent.getParent();
public static class BookmarkDirectory extends DefaultMutableTreeNode {
/** Dates created. */
private Date created;
public BookmarkDirectory(String name) {
super(name);
public void setName(String name) {
setUserObject(name);
public String getName() {
return (String)getUserObject();
public void setCreated(Date date) {
this.created = date;
public Date getCreated() {
return created;
public static class BookmarkEntry extends DefaultMutableTreeNode {
/** User description of the string. */
private String name;
/** The URL the bookmark represents. */
private URL location;
/** Dates the URL was last visited. */
private Date lastVisited;
/** Date the URL was created. */
private Date created;
public void setName(String name) {
this.name = name;
public String getName() {
return name;
public void setLocation(URL location) {
this.location = location;
public URL getLocation() {
return location;
public void setLastVisited(Date date) {
lastVisited = date;
public Date getLastVisited() {
return lastVisited;
public void setCreated(Date date) {
this.created = date;
public Date getCreated() {
return created;
public String toString() {
return getName();
// Bookmarks.java END
// BookmarksModel.java BEGIN
import java.util.Date;
public class BookmarksModel extends DynamicTreeTableModel {
* Names of the columns.
private static final String[] columnNames =
{ "Name", "Location", "Last Visited", "Created" };
* Method names used to access the data to display.
private static final String[] methodNames =
{ "getName", "getLocation", "getLastVisited","getCreated" };
* Method names used to set the data.
private static final String[] setterMethodNames =
{ "setName", "setLocation", "setLastVisited","setCreated" };
private static final Class[] classes =
{ TreeTableModel.class, String.class, Date.class, Date.class };
public BookmarksModel(Bookmarks.BookmarkDirectory root) {
super(root, columnNames, methodNames, setterMethodNames, classes);
public boolean isCellEditable(Object node, int column) {
switch (column) {
case 0:
// Allow editing of the name, as long as not the root.
return (node != getRoot());
case 1:
// Allow editing of the location, as long as not a
// directory
return (node instanceof Bookmarks.BookmarkEntry);
default:
// Don't allow editing of the date fields.
return false;
// BookmarksModel.java END
// DynamicTreeTableModel.java BEGIN
import java.lang.reflect.*;
import javax.swing.tree.*;
public class DynamicTreeTableModel extends AbstractTreeTableModel {
/** Names of the columns, used for the TableModel getColumnName method. */
private String[] columnNames;
private String[] methodNames;
private String[] setterMethodNames;
/** Column classes, used for the TableModel method getColumnClass. */
private Class[] cTypes;
public DynamicTreeTableModel(TreeNode root, String[] columnNames,
String[] getterMethodNames,
String[] setterMethodNames,
Class[] cTypes) {
super(root);
this.columnNames = columnNames;
this.methodNames = getterMethodNames;
this.setterMethodNames = setterMethodNames;
this.cTypes = cTypes;
public int getChildCount(Object node) {
return ((TreeNode)node).getChildCount();
public Object getChild(Object node, int i) {
return ((TreeNode)node).getChildAt(i);
public boolean isLeaf(Object node) {
return ((TreeNode)node).isLeaf();
public int getColumnCount() {
return columnNames.length;
public String getColumnName(int column) {
if (cTypes == null || column < 0 || column >= cTypes.length) {
return null;
return columnNames[column];
public Class getColumnClass(int column) {
if (cTypes == null || column < 0 || column >= cTypes.length) {
return null;
return cTypes[column];
public Object getValueAt(Object node, int column) {
try {
Method method = node.getClass().getMethod(methodNames[column],
null);
if (method != null) {
return method.invoke(node, null);
catch (Throwable th) {}
return null;
* Returns true if there is a setter method name for column
* <code>column</code>. This is set in the constructor.
public boolean isCellEditable(Object node, int column) {
return (setterMethodNames != null &&
setterMethodNames[column] != null);
// Note: This looks up the methods each time! This is rather inefficient;
// it should really be changed to cache matching
// methods/constructors
// based on <code>node</code>'s class, and code>aValue</code>'s
//class.
public void setValueAt(Object aValue, Object node, int column) {
boolean found = false;
try {
// We have to search through all the methods since the
// types may not match up.
Method[] methods = node.getClass().getMethods();
for (int counter = methods.length - 1; counter >= 0; counter--) {
if (methods[counter].getName().equals
(setterMethodNames[column]) && methods[counter].
getParameterTypes() != null && methods[counter].
getParameterTypes().length == 1) {
// We found a matching method
Class param = methods[counter].getParameterTypes()[0];
if (!param.isInstance(aValue)) {
// Yes, we can use the value passed in directly,
// no coercision is necessary!
if (aValue instanceof String &&
((String)aValue).length() == 0) {
// Assume an empty string is null, this is
// probably bogus for here.
aValue = null;
else {
// Have to attempt some sort of coercision.
// See if the expected parameter type has
// a constructor that takes a String.
Constructor cs = param.getConstructor
(new Class[] { String.class });
if (cs != null) {
aValue = cs.newInstance(new Object[]
{ aValue });
else {
aValue = null;
// null either means it was an empty string, or there
// was no translation. Could potentially deal with these
// differently.
methods[counter].invoke(node, new Object[] { aValue });
found = true;
break;
} catch (Throwable th) {
System.out.println("exception: " + th);
if (found) {
// The value changed, fire an event to notify listeners.
TreeNode parent = ((TreeNode)node).getParent();
fireTreeNodesChanged(this, getPathToRoot(parent),
new int[] { getIndexOfChild(parent, node) },
new Object[] { node });
public TreeNode[] getPathToRoot(TreeNode aNode) {
return getPathToRoot(aNode, 0);
private TreeNode[] getPathToRoot(TreeNode aNode, int depth) {
TreeNode[] retNodes;
// This method recurses, traversing towards the root in order
// size the array. On the way back, it fills in the nodes,
// starting from the root and working back to the original node.
/* Check for null, in case someone passed in a null node, or
they passed in an element that isn't rooted at root. */
if(aNode == null) {
if(depth == 0)
return null;
else
retNodes = new TreeNode[depth];
else {
depth++;
if(aNode == root)
retNodes = new TreeNode[depth];
else
retNodes = getPathToRoot(aNode.getParent(), depth);
retNodes[retNodes.length - depth] = aNode;
return retNodes;
// DynamicTreeTableModel.java END
// IconRenderer.java BEGIN
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.plaf.basic.BasicTreeUI;
class IconRenderer extends DefaultTreeCellRenderer
// Color backColor = new Color(0xD0, 0xCC, 0xFF);
Color backColor = new Color(0xF0, 0xF0, 0xE0);
String tipText = "";
JTree tree;
int currRow = 0;
boolean m_selected;
JTable table;
public IconRenderer(JTree tree, JTable table) {
this.table = table;
// setBackground(backColor);
setBackground(Color.GREEN);
setForeground(Color.black);
this.tree = tree;
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected,
boolean expanded, boolean leaf,
int row, boolean hasFocus) {
Object node = null;
super.getTreeCellRendererComponent(
tree, value, selected,
expanded, leaf, row,
hasFocus);
TreePath treePath = tree.getPathForRow(row);
if(treePath != null)
node = treePath.getLastPathComponent();
currRow = row;
m_selected = selected;
DefaultMutableTreeNode itc = null;
if (node instanceof DefaultMutableTreeNode) {
itc = (DefaultMutableTreeNode)node;
setClosedIcon(closedIcon);
setOpenIcon(openIcon);
return this;
/* Override the default to send back different strings for folders and leaves. */
public String getToolTipText() {
return tipText;
* Paints the value. The background is filled based on selected.
public void paint(Graphics g) {
super.paint(g);
Color bColor = null;
if(!m_selected) {
System.out.println(" iconren not sel currRow " + currRow);
if(currRow % 2 == 0) {
bColor = Color.WHITE;
} else {
bColor = backColor;
} else {
bColor = table.getSelectionBackground();
System.out.println("in else selbg = " + bColor);
bColor = new Color(0xF0, 0xCC, 0x92);
System.out.println(" bColor aft = " + bColor);
int imageOffset = -1;
if(bColor != null) {
imageOffset = getLabelStart();
g.setColor(bColor);
if(!m_selected) {
System.out.println(" not sel setting white ");
g.setXORMode(new Color(0xFF, 0xFF, 0xFF));
} else {
// g.setXORMode(new Color(0xCC, 0xCC, 0x9F));
g.setXORMode(new Color(0x00, 0x00, 0x00));
System.out.println(" using color = " + g.getColor());
if(getComponentOrientation().isLeftToRight()) {
g.fillRect(imageOffset, 0, getWidth() - 1 - imageOffset,
getHeight());
} else {
g.fillRect(0, 0, getWidth() - 1 - imageOffset,
getHeight());
private int getLabelStart() {
Icon currentI = getIcon();
if(currentI != null && getText() != null) {
return currentI.getIconWidth() + Math.max(0, getIconTextGap() - 1);
return 0;
// IconRenderer.java END
// IndicatorRenderer.java BEGIN
// import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import javax.swing.table.*;
import javax.swing.table.*;
import javax.swing.plaf.basic.*;
import java.awt.event.*;
import java.util.EventObject;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.Arrays;
class IndicatorRenderer extends DefaultTableCellRenderer {
/** Makes sure the number of displayed in an internationalized
* manner. */
protected NumberFormat formatter;
/** Row that is currently being painted. */
protected int lastRow;
protected int reloadRow;
protected int reloadCounter;
protected TreeTableModel treeTableModel;
protected TreeTableModelAdapter treeTblAdapter;
protected JTable table;
Component renderer = null;
Color backColor = new Color(0xF0, 0xF0, 0xE0);
IndicatorRenderer(TreeTableModelAdapter treeTblAdapter, TreeTableModel treeTableModel) {
setHorizontalAlignment(JLabel.RIGHT);
setFont(new Font("serif", Font.BOLD, 12));
this.treeTableModel = treeTableModel;
this.treeTblAdapter = treeTblAdapter;
* Invoked as part of DefaultTableCellRenderers implemention. Sets
* the text of the label.
public void setValue(Object value) {
/* setText((value == null) ? "---" : formatter.format(value)); */
setText((value == null) ? "---" : (String) value.toString());
* Returns this.
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
renderer = super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);
lastRow = row;
this.table = table;
if(isSelected) {
doMask(hasFocus, isSelected);
} else
setBackground(table.getBackground());
return renderer;
* If the row being painted is also being reloaded this will draw
* a little indicator.
public void paint(Graphics g) {
super.paint(g);
private void doMask(boolean hasFocus, boolean selected) {
maskBackground(hasFocus, selected);
private void maskBackground(boolean hasFocus, boolean selected) {
Color seed = null;
seed = table.getSelectionBackground();
Color color = seed;
if (color != null) {
setBackground(
new Color(0xF0, 0xCC, 0x92));
// IndicatorRenderer.java END
// JTreeTable.java BEGIN
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.util.EventObject;
public class JTreeTable extends JTable {
/** A subclass of JTree. */
protected TreeTableCellRenderer tree;
protected IndicatorRenderer indicatorRenderer = null;
public JTreeTable(TreeTableModel treeTableModel) {
super();
// Creates the tree. It will be used as a renderer and editor.
tree = new TreeTableCellRenderer(treeTableModel);
TreeTableModelAdapter tdap = new TreeTableModelAdapter(treeTableModel, tree);
// Installs a tableModel representing the visible rows in the tree.
super.setModel(tdap);
// Forces the JTable and JTree to share their row selection models.
ListToTreeSelectionModelWrapper selectionWrapper = new
ListToTreeSelectionModelWrapper();
tree.setSelectionModel(selectionWrapper);
setSelectionModel(selectionWrapper.getListSelectionModel());
// Installs the tree editor renderer and editor.
setDefaultRenderer(TreeTableModel.class, tree);
setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor());
indicatorRenderer = new IndicatorRenderer(tdap, treeTableModel);
// No grid.
setShowGrid(false);
// No intercell spacing
setIntercellSpacing(new Dimension(0, 0));
// And update the height of the trees row to match that of
// the table.
//if (tree.getRowHeight() < 1) {
// Metal looks better like this.
setRowHeight(20);
public TableCellRenderer getCellRenderer(int row, int col) {
if(col == 0)
return tree;
else
return indicatorRenderer;
public void updateUI() {
super.updateUI();
if(tree != null) {
tree.updateUI();
// Do this so that the editor is referencing the current renderer
// from the tree. The renderer can potentially change each time
// laf changes.
setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor());
// Use the tree's default foreground and background colors in the
// table.
LookAndFeel.installColorsAndFont(this, "Tree.background",
"Tree.foreground", "Tree.font");
public int getEditingRow() {
return (getColumnClass(editingColumn) == TreeTableModel.class) ? -1 :
editingRow;
private int realEditingRow() {
return editingRow;
public void sizeColumnsToFit(int resizingColumn) {
super.sizeColumnsToFit(resizingColumn);
if (getEditingColumn() != -1 && getColumnClass(editingColumn) ==
TreeTableModel.class) {
Rectangle cellRect = getCellRect(realEditingRow(),
getEditingColumn(), false);
Component component = getEditorComponent();
component.setBounds(cellRect);
component.validate();
public void setRowHeight(int rowHeight) {
super.setRowHeight(rowHeight);
if (tree != null && tree.getRowHeight() != rowHeight) {
tree.setRowHeight(getRowHeight());
public JTree getTree() {
return tree;
public boolean editCellAt(int row, int column, EventObject e){
boolean retValue = super.editCellAt(row, column, e);
if (retValue && getColumnClass(column) == TreeTableModel.class) {
repaint(getCellRect(row, column, false));
return retValue;
public class TreeTableCellRenderer extends JTree implements
TableCellRenderer {
/** Last table/tree row asked to renderer. */
protected int visibleRow;
/** Border to draw around the tree, if this is non-null, it will
* be painted. */
protected Border highlightBorder;
public TreeTableCellRenderer(Tr -
How to set selected all checkboxes in all dataTable's rows?
Hi there,
I'm trying to perform this simple task: having a dataTable with a column containing checkboxes, how can I allow (with a button, a "super" checkbox or so) to simultaneously set selected all checkboxes in all rows?
And - is it possible to do so without calling the submit of the page?
Thanks to everyone!Yes, the paging for <h:dataTable> works pretty good, it manages the task through four methods created in the java code -- DataTable1_firstPageAction(), DataTable1_previousPageAction(), DataTable1_nextPageAction(), DataTable1_lastPageAction() -- without adding any javascript in the jsp page.
Maybe I could test if a java script similar to the <ui:table>'s one fit also the dataTable...
thanks -
Can we set password to our abap code
can we set password to our abap code. so that no one can edit it.
Hi,
REPORT YEDULOCK.
* This program switches the editor lock flag of a given ABAP program.
* It can be useful when the owner of the ABAP is on holiday ...
TABLES: TRDIR.
PARAMETERS: PRG_NAME LIKE TRDIR-NAME.
SELECT SINGLE * FROM TRDIR WHERE NAME = PRG_NAME.
IF SY-SUBRC = 0.
IF TRDIR-EDTX = ' '.
TRDIR-EDTX = 'X'.
ELSE.
TRDIR-EDTX = ' '.
ENDIF.
MODIFY TRDIR.
IF SY-SUBRC = 0.
WRITE: / 'Successful switch.'.
COMMIT WORK.
ELSE.
WRITE: / 'Failed switch.'.
ENDIF.
ELSE.
WRITE: / PRG_NAME, ' does not exist.'.
ENDIF.
Regards
Sudheer -
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 value for table lines in web dynpro ?
Hi experts,
I'm new in webdynpro. My requirement is to set value to the second line when user press expand on first line.
In method ONACTIONLOAD_CHILDREN , I use get_static_attributes_table to get the current table records and change return table value .
Then i user bind_table to pass table to the screen.
It works fine for first time i press expand and collaps, but when i expand it again it throw out a dump 'OBJECTS_OBJREF_NOT_ASSIGNED'.
Could any one please help to solve that?
ThanksHi Harsha,
Thanks for your reply,I've check the dump details and it display like this:
Information on where terminated
Termination occurred in the ABAP program "CL_WDR_CONTEXT_ELEMENT========CP" -
in "IF_WD_CONTEXT_ELEMENT~SET_ATTRIBUTE".
The main program was "SAPMHTTP ".
In the source code you have the termination point in line 40
of the (Include) program "CL_WDR_CONTEXT_ELEMENT========CM007".
The termination is caused because exception "CX_SY_REF_IS_INITIAL" occurred in
procedure "IF_WD_CONTEXT_ELEMENT~SET_ATTRIBUTE" "(METHOD)", but it was neither
handled locally nor declared
in the RAISING clause of its signature.
The procedure is in program "CL_WDR_CONTEXT_ELEMENT========CP "; its source
code begins in line
1 of the (Include program "CL_WDR_CONTEXT_ELEMENT========CM007 ".
First time i debug it work fine but the next time it dump with same import values. And it even did not reach the logic i add when i expand it again.
I'm not sure why it happen.
My code in ONACTIONLOAD_CHILDREN is like this.
*navigate from <CONTEXT> to <ITEM_DATA> via lead selection
lo_nd_item_data = wd_context->path_get_node( path =
`COMP_CONTEXT.ITEM_DATA` ).
*get element via lead selection
lo_el_item_data = lo_nd_item_data->get_element( ).
*get all declared attributes
lo_nd_item_data->get_static_attributes_table(
IMPORTING
table = lt_item_data ).
LOOP AT lt_item_data INTO ls_item_data.
IF sy-tabix = 2.
ls_item_data-description = 'TEST'.
MODIFY lt_item_data FROM ls_item_data TRANSPORTING description.
ENDIF.
ENDLOOP.
lo_nd_item_data->bind_table( new_items = lt_item_data
set_initial_elements = abap_true ).
lo_nd_item_data->set_lead_selection_index( 1 ).
First line was set selected but still got dump.
Could you please help to check this ?
Thanks & Regards
Eric Li -
SRM MDM, Error, "Table with Code 'null' does not exist in repository"
Hi experts,
We has SRM MDM scenario, while doing OCI settings, we are able to connect with MDM repository but getting follwoing error message in portal, "java.lang.IllegalArgumentException: Table with Code 'null' does not exist in the repository 'Repository' or is one of the system table (e.g. Workflows) that is not exposed in repository schema"
Can You please suggest,
Thanks and Regards,
MunishHi everyone,
Sudhanshu and Anshuk:- Thanks for your response, let me try and explain the real scenario in details:-
We have deployed the SRM-MDM Catalog Search UI in Portal.
We tried accessing the http://<Portal Host>:<Portal Port>/SRM-MDM/SRM_MDM
Then we got a screen (Search UI App screen), where in we have provided the MDM Server name, then the MDM Server Password, then presses the Connect button, then below this, it displayed the Repository name created in the MDM. We have selected the Repository, then provided the Credentials of a User (Name: T_CORP) in MDM which has "Catalog Manager", and the "UI Configuration Manager" Roles. Please note that these Role names were created by us in MDM. Is it the right procedure or do we have any standard Roles delivered by SAP in MDM to map? If any standard Roles are available, where we need to check these.
Once the Credentials of MDM User is provided, and then selected the "Login" button.
Then we are getting the below error.
"java.lang.IllegalArgumentException: Table with Code 'null' does not exist in the repository 'Repository' or is one of the system table (e.g. Workflows) that is not exposed in repository schema"
Please clarify; we are not configuring any values in iViews. Where we need to do this, I mean name of the iView, and what values do we need provide generally? We are just running the Search UI App application; I don't think it is an iView, because the URL shows the Application name details, etc...
Please guide us, how to fix this Error.
Thanks and Regards,
Munish -
Error when selecting bkpf table
select single belnr
into it_data-belnr
from bkpf
where awkey = it_vbrp1-vbeln and
blart = 'RV'.
above code i am using for selecting bkpf table , actually key field are not useful in this case & hws to use index.
plz reply.
Thanks,
JyotsnaHi,
select single belnr
into it_data-belnr
from bkpf
where awkey = it_vbrp1-vbeln and
blart = 'RV'.
In above query what is it_vbrp1-vbeln? if it is internal table you are missing some thing like For all entries in it_vbrp1.Check it once. -
KUP-01005 error when selecting external table
Hi All,
My name is arun. I am having trouble resolving the following error. I tried to google, search oracle forum but no avail. I would really appreciate some help? I hope someone point me to the right direction with this problem. Thank you.
Scenario :
I have done the following :
1. Created the external directories using a user account(KDEV199). However by default its owned by SYS user.
2. Created the table necessary for selection. This was done by user account(KDEV199)
3. I have granted the folder privileges owned by oinstall:oracle where the 2 physical files exists. Thus all the files is owned by oracle. This was done at OS layer.
4. I have created 2 files necessary to extract data & read in oracle. This was done at OS layer.
The problem is that i have the following when i try to select the table :
SQL> select * from TEXN_IGM_MST;
select * from TEXN_IGM_MST
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-00554: error encountered while parsing access parameters
KUP-01005: syntax error: found "minussign": expecting one of:
"double-quoted-string, identifier, single-quoted-string"
KUP-01007: at line 7 column 10
This script used to create the table :
--Create External Table
CREATE TABLE texn_igm_mst
COMP_NO CHAR(2),
POL_NO CHAR(10),
WRITING_AGENCY_NO_1 CHAR(10),
WRITING_AGENT_NO_1 CHAR(10),
WRITING_AGENCY_NO_2 CHAR(10),
WRITING_AGENT_NO_2 CHAR(10),
POL_STS_CDE CHAR(4),
STS_CHNG_DT DATE,
POL_DTE DATE,
PAY_UP_DTE DATE,
PAY_TO_DTE CHAR(10),
MATURE_DTE DATE,
PAY_MODE_CDE CHAR(2),
PAY_METHOD_CDE CHAR(1),
MODAL_PREM_AMT NUMBER(15,2),
POL_CUR CHAR(2),
NFO_CDE CHAR(1),
DIVD_OPTION_CDE_1 CHAR(1),
DIVD_OPTION_CDE_2 CHAR(1),
OTHER_OPTION_CDE_1 CHAR(1),
OTHER_OPTION_CDE_2 CHAR(1),
RESTRICT_CDE CHAR(20),
NEXT_MODAL_PREM NUMBER(15,2),
SUSPEND_CDE CHAR(1),
EXTRACT_DTE DATE,
REASON_CDE CHAR(3),
LINE_OF_BUSS CHAR(1),
BILL_TO_DTE CHAR(10),
DUE_DAY NUMBER(3),
DAY_USE CHAR(1),
PAR_TYPE CHAR(1),
ISSUE_STATE CHAR(2),
MED_CDE CHAR(1),
RACE_CDE CHAR(1),
ADMIT_CDE CHAR(1),
REPT_STATE CHAR(2),
COLL_OFF CHAR(2),
WRITING_AGENCY CHAR(10),
LAST_ANN_PROC CHAR(3),
TIMESTAMP DATE,
SPND_EFF_DT DATE,
SPND_TRMN_DT DATE,
SPND_USER_ID CHAR(8),
CMPLN_AGT_ID CHAR(10),
TOTAL_CWA DECIMAL(17),
TOTAL_CWA_DT DATE,
DELIVERY_DT DATE,
REINSURED_CDE CHAR(1),
SERV_AGENCY CHAR(10),
ST_CODE CHAR(1),
NFO_RULE CHAR(1),
CSTAT_REASN_CD CHAR(2),
REJ_REASN_CD CHAR(2)
ORGANIZATION EXTERNAL
TYPE oracle_loader
DEFAULT DIRECTORY external_dir_clmlog
ACCESS PARAMETERS
records delimited by newline
BADFILE external_dir_clmlog:'VILFPM1.BAD'
LOGFILE external_dir_clmlog:'VILFPM1.LOG'
fields terminated by '!'
missing field values are null
--Column and format setting
COMP_NO,
POL_NO,
WRITING_AGENCY_NO_1,
WRITING_AGENT_NO_1,
WRITING_AGENCY_NO_2,
WRITING_AGENT_NO_2,
POL_STS_CDE,
STS_CHNG_DT CHAR date_format DATE Mask "yyyy-mm-dd",
POL_DTE CHAR date_format DATE Mask "yyyy-mm-dd",
PAY_UP_DTE CHAR date_format DATE Mask "yyyy-mm-dd",
PAY_TO_DTE,
MATURE_DTE CHAR date_format DATE Mask "yyyy-mm-dd",
PAY_MODE_CDE,
PAY_METHOD_CDE,
MODAL_PREM_AMT,
POL_CUR,
NFO_CDE,
DIVD_OPTION_CDE_1,
DIVD_OPTION_CDE_2,
OTHER_OPTION_CDE_1,
OTHER_OPTION_CDE_2,
RESTRICT_CDE,
NEXT_MODAL_PREM,
SUSPEND_CDE,
EXTRACT_DTE CHAR date_format DATE Mask "yyyy-mm-dd",
REASON_CDE,
LINE_OF_BUSS,
BILL_TO_DTE,
DUE_DAY,
DAY_USE,
PAR_TYPE,
ISSUE_STATE,
MED_CDE,
RACE_CDE,
ADMIT_CDE,
REPT_STATE,
COLL_OFF,
WRITING_AGENCY,
LAST_ANN_PROC,
TIMESTAMP CHAR date_format DATE Mask "yyyy-mm-dd-hh24.mi.ss.ffffff",
SPND_EFF_DT CHAR date_format DATE Mask "yyyy-mm-dd",
SPND_TRMN_DT CHAR date_format DATE Mask "yyyy-mm-dd",
SPND_USER_ID,
CMPLN_AGT_ID,
TOTAL_CWA,
TOTAL_CWA_DT CHAR date_format DATE Mask "yyyy-mm-dd",
DELIVERY_DT CHAR date_format DATE Mask "yyyy-mm-dd",
REINSURED_CDE,
SERV_AGENCY,
ST_CODE,
NFO_RULE,
CSTAT_REASN_CD,
REJ_REASN_CD
LOCATION (external_dir_clmxcom:'VILFPM1.DAT')
DB version :
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
OS version :
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 1
Linux KAITLSDS01 2.6.32.12-0.7-default #1 SMP 2010-05-20 11:14:20 +0200 x86_64 x86_64 x86_64 GNU/Linux
---------------------------------------------------------------------------------------------------------------------------------------Pl see MOS Doc 302672.1 (Select From External Table Gives ORA-29913 ORA-29400 KUP-554 KUP-1005)
Srini -
"Select" Physical table as LTS for a Fact table
Hi,
I am very new to OBIEE, still in the learning phase.
Scenario 1:
I have a "Select" Physical table which is joined (inner join) to a Fact table in the Physical layer. I have other dimensions joined to this fact table.
In BMM, I created a logical table for the fact table with 2 Logical Table Sources (the fact table & the select physical table). No errors in the consistency check.
When I create an analysis with columns from the fact table and the select table, I don't see any data for the select table column.
Scenario 2:
In this scenario, I created an inner join between "Select" physical table and a Dimension table instead of the Fact table.
In BMM, I created a logical table for the dimension table with 2 Logical Table Sources (the dimension table & the select physical table). No errors in the consistency check.
When I create an analysis with columns from the dimension table and the select table, I see data for all the columns.
What am I missing here? Why is it not working in first scenario?
Any help is greatly appreciated.
Thanks,
SPHi,
If I understand your description correctly, then your materialized view skips some dimensions (infrequent ones). However, when you reference these skipped dimensions in filters, the queries are hitting the materialized view and failing as these values do not exist. In this case, you could resolve it as follows
1. Create dimensional hierarchies for all dimensions.
2. In the fact table's logical sources set the content tabs properly. (Yes, I think this is it).
When you skipped some dimensions, the grain of the new fact source (the materialized view in this case) is changed. For example:
Say a fact is available with the keys for Product, Customer, Promotion dimensions. The grain for this is Product * Customer * Promotion
Say another fact is available with the keys for Product, Customer. The grain for this is Product * Customer (In fact, I would say it is Product * Customer * Promotion Total).
So in the second case, the grain of the table is changed. So setting appropriate content levels for these sources would automatically switch the sources.
So, I request you to try these settings and let me know if it works.
Thank you,
Dhar -
Importing from a set of Oracle tables with a minimum development effort - SSIS 2012
Hi,
I'd like to import into a SQL Server 2012 db a set of Oracle table without creating a specific data flow task for each table to import. Is it possible to accomplish a such task?
ThanksHi pscorca,
As Arthur suggested, the simplest approach is to make use of the SQL Server Import and Export Wizard. This tool enable us to select multiple Orace tables at one time, and even create the destination table automatically. Then, we can save it
as a package without running it immediately. In this way, there are multiple Data Flow Task created automatically for each source table.
Regards,
Mike Yin
TechNet Community Support -
How to create a "Selection Conditions" table similar to that found in se11?
Hi,
My team is trying to develop a SAP data migration tool (DMT) using ABAP.
One of the functionalities in the DMT is to validate the data imported to the staging area tables against some reference tables (e.g. SAP tables).
To do this, I would need to have a "Selection Conditions" table similar to that found in se11 (se11--> Display "View" --> Select "Selection Conditions" tab). This table would allow me to specify my 'referencing' conditions (e.g. Table = "ZMYTAB", Field = "ZMYFLD", OPERATOR = "EQ", Comparison Value = "ZMYTAB2", AND/OR = "").
Are there any ready-made codes out there for such a "Selection Conditions" table? Or did SAP provide a built-in object for such a table?
Any help would be greatly appreciated. Thanks!personnally I do use the standard FMs for dynamic selections
see FM FREE_SELECTIONS_DIALOG
Look at this sample code:
http://sap.ittoolbox.com/code/archives.asp?i=10&d=2919&a=s -
Disable the Dynamic Selection Icon from T.Code FBL1N
Hi,
I want to disable the Dynamic Selection Icon from T.Code FBL1N...
Please Note that i found a link where some code is given for this problem.
Remove the dynamic selection screen.......
Please tell me where i paste that code....after initialization or where....
Thanks...
Edited by: Prince Kumar on May 16, 2009 8:59 AMHi,
1) COPY the program RFITEMAP and create a ZRFITEMAP
2) and added this code in the INITILIZATION event. You can search ZRFITEMAP with INITIALIZATION and add below code there.
INTIALIZATION.
DATA: t_exclude TYPE STANDARD TABLE OF sypfkey.
APPEND 'DYNS' TO t_exclude.
"DYNS is the dynamic selection screen function code.
CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
EXPORTING
p_status = sy-pfkey
TABLES
p_exclude = t_exclude
Regards
Shital
Maybe you are looking for
-
Why does my mac reboot on its own?
Why does my mac reboot on its own?
-
Error in IE or Error in my Code..Need Help.
Hi! all.. I am trying to use page indices (using <A NAME> and <A HREF> tags) with grouping using CFML and SQL on a long page..so that i don't have to do scroll down.. I have a SQL table containing names, address, city, state and zipcode. I am fetchin
-
Waiting for Approval - RFx Question
Hi Experts, We are in Esourcing 7.0. My Client has a requirement to add spend category group as approver for RFx before it go to next phase 'Open for Review'. I modified the document security template for RFx and provided the group information. Added
-
IPhoto '08 won't recognize photo DB
Before I updated my macbook to mountain lion I used time machine to back everything up. I did the OS install, then reinstalled iPhoto '08 and the iPhoto library onto the macbook. Now iPhoto opens fine, but it says there are no photos. I can't figu
-
My Iphone 5S is DEAD (only images Cable and disc)/. My imei : 013886000503612. I had try use itunes 11.4 for update an recovery but about 99 % itunes display :The iphone "iPhone" could not be restore>An unknow error occured(3). what can i do now? im