Swing/AWT/SWT :: Color To Persist In Cell Of Jtable After ComboBox Selection

May 29, 2014

I have a ComboBox I'm using for a cellEditor. The list of items in the comboBox might have colors behind them, which I've managed to render. What I haven't figured out is a good way to keep the color in the cell after the item is selected.I don't' want to have a persistent comboBox in the cell, i only want to see it when editing that cell.

public TableCellEditor getCellEditor(int row, int col)
{
if (row==theRow && col==theCol)
{
JComboBox<?> combo = new JComboBox<Object>(getPickListEntries());
combo.setRenderer(new PickListRenderer(combo));
combo.setBorder(BorderFactory.createEmptyBorder());
}

[code]....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: JTable - Cell Keeps Focus After Clear Selection

May 7, 2014

I'm having a small problem using a jTable.

After calling the .clearSelection() methode of the table object, the cell clicked in when selecting the table row, keeps it's focus.

How do I remove the focus of the cell?

View Replies View Related

Swing/AWT/SWT :: Changing Color Of Jtable Base On A Row Of Cell Value In One Column

Feb 10, 2014

My code is

Double qty = 0.0;
for ( int i = 0; i < ingTable.getRowCount(); i++){
qty = (Double) ingTable.getValueAt(i,2);
if( qty < 30.0){
ingTable.setBackground(Color.red);
} else {
ingTable.setBackground(Color.white);
}
}

View Replies View Related

Swing/AWT/SWT :: How To Change Color Of Column Header When Cell Is Clicked In JTable

Jan 20, 2015

I'm working on a spreadsheet-like table and I was able to set it so that it would highlight the first cell in the relevant row(titled 1,2,3.. etc) when a cell is clicked. (Just like in MS Excel - preview attached) Now I want to do the same to the column header(i.e. A,B,C,D....etc) . How can I do it?

private void formWindowOpened(java.awt.event.WindowEvent evt) {
setLocationRelativeTo(null);
int rowNum = sheet.getRowCount();
for(int i=0; i<rowNum; i++){
sheet.setValueAt(i+1, i, 0);

[Code] .....

Untitled.jpg

View Replies View Related

JSP :: How To Persist User Previous Selection Of Radio Button

Sep 28, 2014

I am making a quiz app and stuck with this problem. User is presented with question with options he select one radio button and move on to next question by clicking next button.

Now when user clicks on the previous button to change the previous selction , I want his previous selection to be shown selected. How can I do that.

View Replies View Related

Swing/AWT/SWT :: How To Get Double Value Into JTable Cell

May 29, 2014

My latest issue was that I wanted to only get a double value into a JTable Cell.

So first I Overrode the getCellEditor(int row,int col) method of my JTable, so if I was in a cell i knew I needed a double value I returned my Editor.

My editor filters out anything but numbers. I also check to make sure we get one and only one decimal point.

Other solutions Ive seen use keyboard Listeners, but to me that doesn't work. What if the user cuts and pastes data? My solution handles that as well.

It doesn't handle if they try to cut and paste something like 1234abcd.bob.123.23 , this would result in 1234..123.23 pasted in. I'll handle faulty values on the getValue method of my AbstractTable, but as long as the user is using mostly valid data this works well.

public TableCellEditor getCellEditor(int row, int col) {
if (row==TheRowWant && col==TheColumnI want) {
return (new DefaultCellEditor(createDoubleTextField()));
}
}
private JTextField createDoubleTextField() {
final JTextField field = new JTextField();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Peculiar JTable - Cell Value Vanishes

Aug 20, 2014

I am facing some peculiar issue with JTable.

Change value of a cell, without clicking on anywhere else, directly click on column (or) try to expand column size, value you entered in that cell vanishes. But if you click on any other cell instead of expanding column size, value will remain in cell. Not really sure how to fix this issue.

class SimpleTableExample
extends JFrame
{
// Instance attributes used in this example
privateJPaneltopPanel;
privateJTabletable;
privateJScrollPane scrollPane;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: JTable Using CTRL / Click For Multiple Row Selection

Jul 6, 2014

I know how to do single selection, but I would like to do multiple row selection only by using CTRL + click without the option of dragging the mouse to select rows. So the user would have to hit ctrl + click each time to highlight additional rows.

View Replies View Related

Swing/AWT/SWT :: Custom JTable Renderer And Cell Editor

Jul 23, 2014

What I'm trying to do is make an inventory type program that includes a jtable. In the Jtable in the last column there will be 2 buttons and a textfield to register the value of additions or subtractions to the overal stock amount. (See screenshot in attachment).

As of now I am able to increment or decrement the numbers when the buttons are clicked on however the problem is that if I add 2 to the first row, and then go to add 2 to the next row or any other row for that matter, the value of the previous row is added to the next row, and the previous row reverts back to a value of 0. So basically its like there is only one editor that keeps track of one value no matter what row you are editing.

I need getting it so that I can add different values to each different row depending on the stock being used or received. The following is my code:

Main class

JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 155, 643, 233);
IMG.add(scrollPane);
center = new centerJustify();
ts = new tableCellRenderer();
tm = new DefaultTableModel(){

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Making A Custom Cell Renderer Work In A JTable?

Jan 24, 2014

Now my issue is I have a JTable. The first column will contain Date objects all the way to the bottom. I want the JTable to display only the month and year. I created a custom cell renderer, but it appears the cell renderer method "getTableCellRendererComponent" is never called. (I tested it using System.out.println();) Here is my code for setting the cell renderer and the contents of the first column:

MonthYearTableCellRenderer renderer = new MonthYearTableCellRenderer();
tblView.setDefaultRenderer(Date.class, renderer);
for(int i = 0; i < 60; i++){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.MONTH, i);
tableModel.setValueAt(cal.getTime(), i, 0);
}

The Date objects are set into the cells of column 0 correctly. The table shows the result of the "toString()" method for each cell in that column.

View Replies View Related

Swing/AWT/SWT :: Copy Selected Data From JTable Cell To Clipboard

Feb 18, 2014

I have a jtable that I would like to copy from a cell that I select to clipboard. How could I do these.

View Replies View Related

Swing/AWT/SWT :: Update JTable Cell Values Inside A Loop

Jan 5, 2015

I have a program where i want to indicate the user when i have completed a task which i am running inside a for loop. Below is my code.

for(Map.Entry<Double,SimplestCopyInstance> entry : myList.entrySet()){
double key = entry.getKey();
SimplestCopyInstance scp = entry.getValue();
Copy cp = new Copy();
cp.putLocations(scp.getSrc(), scp.getDes());
scp.setStatus(cp.baseCopy()+"");

[Code] ....

I have used netbeans to build my app. So there creating jTable is out of my control as that part was inside auto-generated code. I have just used the jTable.setValue().

My problem is, above method is inside a button click event. Updated values not displaying until the loops ends.

View Replies View Related

Swing/AWT/SWT :: JTable Cell Renderer Causing Program To Go Black When Minimized

Aug 25, 2014

I'm making a program that selects classes from a database via a jcombo box and then populates a time table with the class times.

I've used a custom cellrenderer that extends DefaultTableCellRenderer to text wrap the information and change the background of the cells.

It works but when i minimize the program it goes all black and if I double click I get a new JTextArea opening up on the timetable and when I minimize the program and go to open it again i get an "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" and the cell render seems to be called again even though i haven't rerun the program.

This is the cell renderer that I built

public class TimesTableCellRenderer extends DefaultTableCellRenderer {
private int minHeight = -1;
private final JLabel label = new JLabel();
private final JTextArea textArea = new JTextArea();
public TimesTableCellRenderer(){
super();
textArea.setLineWrap(true);

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Code Prevent Cursor From Moving When Inside A Cell Of JTable

Jun 24, 2014

Tried creating a simple sample but all works as expected.

The following code prevents the cursor from moving when inside a cell of a JTable.

public void keyPressed(KeyEvent e) {
if ( (e.getKeyCode() == KeyEvent.VK_KP_LEFT) || (e.getKeyCode() == KeyEvent.VK_KP_RIGHT)
|| (e.getKeyCode() == KeyEvent.VK_RIGHT) || (e.getKeyCode() == KeyEvent.VK_LEFT) )
{
//Do nothing
e.consume();
}
}
});

When editing a cell, the existing code would use the right/left cursor keys to move from cell to cell as opposed to from character to character when editing a cell. I planned to override the functionality by tossing in the above code as a test to see if it stops the functionality before I override it.

After placing in the above code, the above functionality no longer occurs, but now the cursor moves within the cell as I wanted which is to move from character to character instead of cell to cell. Its great it works, but it really shouldn't. Essentially the default behavior has been restored when it should have really disabled the left/right keys.

I assume there is some underlying class someplace that is doing something to affect the behavior. Since a sample can't be provided I am wondering in what scenarios would the e.consume() restore default functionality?

View Replies View Related

JavaFX 2.0 :: TableView Single Cell Selection Styling

Jun 6, 2014

TableView selection model allows selecting single cells in the table but the default styling highlights the whole row regardless of the actual column selected in the row.

I am just wondering what options are there to change this behaviour so that the actual cell (row/column) get highlighted rather then the whole row.

Something like the $18,000 cell in the  "Figure 1 Table overview"  in [URL] ....

View Replies View Related

Combobox To Change Color And Shape

Nov 19, 2014

i java a project with java draw golf course and currently working on 2 combo boxes to change shape of the flag on the post and fill color as well on combo box item change. I have below code. as am new to java what to do next.

import java.awt.*;
import java.awt.event.ItemEvent;
import javax.swing.*;
public class GulfCourse extends JPanel{
public void paintComponent( Graphics g){
super.paintComponents(g);
//draw green oval

[Code]...

View Replies View Related

How To Change Color Of Column Header When Cell Is Clicked

Jan 21, 2015

I'm working on a spreadsheet-like table and I was able to set it so that it would highlight the first cell in the relevant row(titled 1,2,3.. etc) when a cell is clicked. (Just like in MS Excel - preview attached) Now I want to do the same to the column header(i.e. A,B,C,D....etc) . How can I do it?

private void formWindowOpened(java.awt.event.WindowEvent evt) {
setLocationRelativeTo(null);
int rowNum = sheet.getRowCount();
for(int i=0; i<rowNum; i++){
sheet.setValueAt(i+1, i, 0);

[Code] ......

View Replies View Related

How To Populate JTable By Selecting ComboBox Value

Sep 25, 2014

How can I populate the jTable in my form by selecting value from combo box. And remember I have database as well.

View Replies View Related

JButton In A JTable Cell

Aug 19, 2014

How do i parse a String of text in a JTable Cell to work as a button?For example lets say a row of IDs such as 1,2,3,4,5,6 id like the whole column to parse as JButtons that are titled 1,2,3,4,5,6..Id like to then use these buttons to call a function with the title as a parameter.Its just a simple row of entries where the button will open up an edit screen to edit the corresponding clicked entry.So how do i parse them as buttons for a start?

View Replies View Related

JTable Specific Cell Selected

Jun 6, 2014

I want perform some calculations whenever a specific cell block is focused in JTable, I've tried using focusListener on JTable but looks like my table isn't triggering the event. I don't know why, what to do?

View Replies View Related

Key Binding JTable Cell Entries

Jul 8, 2014

I have an editable JTable that has a lot of JComboBox's as cell entries. I would like to be able to "arrow over" to said cell, and with a pressing of either a numerical button or by typing the first letter of the String selection (possibly followed by a second), be able to select the appropriate selection from the cell's JComboBox. I have tried to add a key listener to the JComboBox itself, which works given that I click on said cell and show its menu.

How would I go about ensuring that, when focus is on the cell itself, and I start typing, the appropriate selection is chosen?? (I think this might get into key binding, but I don't know if I have to try it from the scope of JTable, or from that JTable's TableModel (which I have made my custom version of).

Here is what I have so far (everything but SandwichNumber, SandwichName, and Oregano uses JComboBox): [URL] ...., how would I do such key binding?

View Replies View Related

How To Merge Cell In DefaultTableModel / JTable

Feb 18, 2014

I searched a lot and got some answers for this Q. but many of them referred to links which give 404 error. I want to make table like this:

Can I make this in Java?

View Replies View Related

Jtable Cell With Search Depends On Value Entered?

May 31, 2014

I am trying to do the fallowing ,

Jtable cell with search (% like) depends on the value entered

if i enter "mi" it should show all data begin with "mi" from my data set

View Replies View Related

JTable With ImageIcon - How To Use Array With 4 Values In Table Cell

Mar 22, 2015

I would like to create a JTable.
 
Each cell contains an array of 4 objects:

[0] ImageIcon
[1] ImageIcon
[2] Number
[3] Boolean

1) Once JTable is displayed, each cell display only [0] .
2) Later, based on user mouse click on cell, cell should display [1]
 
How can I use an array with 4 values in Table Cell?

View Replies View Related

Jump Games - Put Images Into JTable For Organization And Character Selection Purposes

Jul 14, 2014

HTML Code:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.Border;
import javax.imageio.ImageIO;
public class Main extends JApplet implements Runnable, ActionListener {

[Code] .....

I am making a game and there are two problems that I have and can't seem to solve. I never made on applet before, and I'm not good with the swing components, but I am decent programming in Java.

Problem #1: the start button is in the JPanel, I don't want that, I want it to be above the JPanel.
Problem #2: I want to put images in to a JTable for organization and character selection purposes, but I keep on getting a string. Do I have to use an ImageIcon to get it to work, or does it matter?

In case you were wonder what kind of game I'm making, I'm making one of those jump games where you jump on platforms and try to go as high as you can without missing a platform. There is going to be character selection for the jumper, and the jumpers are going to be food, like a potato, a banana, a strawberry, etc.

View Replies View Related

Color One Column In JTable

Jan 6, 2015

how I can highlight one column with color? When i add color to a column the entire table is colored.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved