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


ADVERTISEMENT

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 :: Using Same Cell Renderer Object For A Number Of Cells?

May 28, 2014

I have a number of cells which are Dates and need to have them appear in the same format. The samples I have seen usually create a new cell renderer object for each cell, even if its the same type. Since I have a number of Date cells I thought it best to use a single object for each of the date cells, but after seeing the different samples I am wondering if there is something I may be missing where using the same cell renderer object could potentially be an issue.

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 - 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 :: 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 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 :: 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

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

Swing/AWT/SWT :: Notification Window Minimized As The Messenger

Feb 17, 2014

I need that when my application is minimized notify you when something happens, like the messenger (MSN) remember? The window notifying a new message, the minimized window blink in orange, orange need not be ok? I do not even know where to start.

View Replies View Related

Swing/AWT/SWT :: Custom Jtree Renderer

Nov 2, 2014

I would like to ask about JTree custom renderer. What could be wrong with this. Here's the deal:

I have a Jtree which suppose to view the structure of given folder, so far so good its working. But my problem is that i dont want it to show the full path as name, only folder name and file name. I wrote a custom JTree renderer in hope that this will solve my problem but it didn't.

Here is my custom Jtree renderer:

private static class MyTreeCellRenderer extends DefaultTreeCellRenderer {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if( value instanceof DefaultMutableTreeNode){

[Code] .....

and here is where I am trying to implement it:

tree.setCellRenderer( new MyTreeCellRenderer());

View Replies View Related

Nested For Loop Causing Program To Crash

Jan 23, 2015

Implementation of the nested for loop. I thought it was going to go smoothly but apparently not.Purpose: This program is meant to print out all the prime numbers up to a certain range using the algorithm Sieve of Eratosthenes.

Update output: Works as expected.

Java Code:

import java.util.Scanner;
import java.util.ArrayList;
public class PrimeFactors
{
static ArrayList<Double> primeList = new ArrayList<>();
static double range = 0;
static double maxPrime = 0;
static double primeTester = 0;

[code]....

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

Custom Jtable Cell Editor Throwing Illegal Component State Exception

Jul 10, 2014

I've come across an interesting problem when using a Jcombobox as a custom cell editor(and renderer) in a jtable. I was hoping to add a keybinding in order to display the dropdown of the combobox instead of having to click on it however, when I make a call to showPopup() I get:

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location Which is strange as my jtable is visible and the editor/renderer seems to be working fine.

Here's the cell editor + renderer I'm using:

class MyComboBoxRenderer extends JComboBox implements TableCellRenderer {
public MyComboBoxRenderer(String[] items) {
super(items);
} public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());

[code]....

View Replies View Related

Search Algorithm Causing StackOverFlowError?

Apr 29, 2015

I am using what is known as a Depth First Search to solve a maze using my own Stack created class for an assignment. The reason I believe I am getting this error is because my program is never meeting the `finishSpot` condition. I have used the debugger and it looks like it is infinitely stuck at the Point before the `finishSpot`. My logic seems to be mostly correct except until the point where my maze solver tries to finish the maze.

This is a sample maze:

*****
*s* *
* * *
* f*
*****

Here is my Main which uses my created Stack class.

//Creates a Stack and determines the start and endpoints.
public static void solveDFS( char [][] maze ){
LinkedStack stack = new LinkedStack();
Point currentSpot = findPoint( maze,'s' );
Point finishSpot = findPoint( maze, 'f' );
findPath( maze,currentSpot, finishSpot,stack );

[code]....

View Replies View Related

Array Is Not The Right Size - Causing Errors

Oct 17, 2014

protected void randomise() {
int[] copy = new int[];
// used to indicate if elements have been used
boolean[] used = new boolean[array().length];
Arrays.fill(used,false);
for (int index = 0; index < array().length {

[Code] .....

View Replies View Related

Switching Security On In WTP Eclipse Plugin Causing Massive Errors

Aug 15, 2014

I am working on an Eclipse based project that uses WTP Eclipse plugin. Since I have switched security on in that plugin (by checking "Enable Security" check box on) I'm having multiple problems. I get a stack of security errors - attached in this post. I also show my java.policy file. Because the of the mass exceptions I list only the top, although I have attached a docx file with full thing.

Here is my java.policy file:

grant codeBase "file:${catalina.base}/wtpwebapps/App/WEB-INF/lib/hibernate-core-4.3.5.Final.jar" {
permission java.util.PropertyPermission "*", "read, write";
};
grant codeBase "file:${catalina.home}/lib/catalina.jar" {
permission java.lang.RuntimePermission "*";

[Code] ....

Exceptions:

15/08/2014 10:12:43 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:
C:Javajdk1.6.0_33in;C:WINDOWSSunJavain;
C:WINDOWSsystem32;C:WINDOWS;

[Code] .....

View Replies View Related







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