Nadin Jovan

Greenhorn
+ Follow
since Aug 12, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nadin Jovan

This is the code I used to play a sound in my program that will notify the user the something has happened.
URL url = //url to the wav file I want played
AudioClip clip = Applet.newAudioClip(url);
clip.play();
What I am experiencing is that the sounds is played sometimes and sometimes not. It is played more offten than not, but still it happens that sometimes it is not. Am I doing something wrong? Any suggestions what might be the problem? Thanks.
16 years ago
I am trying to modify the default renderer for Boolean class to disable certain JCheckBox cells in a table.
I overwrote the method getCellRenderer as follows:
public TableCellRenderer getCellRenderer(int row, int col) {
if (col == 0) return this.getDefaultRenderer(String.class);

if (!this.getModel().isCellEditable(row, col)) {
TableCellRenderer renderer = this.getDefaultRenderer(Boolean.class);
if (renderer instanceof JCheckBox) {
JCheckBox box = (JCheckBox)renderer;
box.setEnabled(false);
box.setBorderPaintedFlat(true);
//box.setForeground(Color.LIGHT_GRAY);
//box.setBackground(Color.BLUE);
}
return renderer;
}
return this.getDefaultRenderer(Boolean.class);
}
I would expect this to render all uneditable cells as disabled JCheckBoxes, but it didn't.
Any ideas what I might be doing wrong?
Thanks.
16 years ago
I have a table in which main diagonal should be disabled for selection.
Users should be able to click on the remaining cells in order to turn them on or off. I would like to disable the main diagonal so that it is clear to the user that those cannot be changed.
What I did is, I created a subclass of the AbstractTableModel class and in that class I overwrote isCellEditable(int row, int column) method as follows:
public boolean isCellEditable(int row, int col) {
boolean result = (row >= 0 && col >= 1 && row != (col - 1));
return result;
}
So this will not allow user to modify cells on the main diagonal. However, these cells look the same as the rest of the cells in the table (they are always off and they cannot be modified). I would like to disable them in some obvious and visible way, like when a CheckBox is disabled. Is that possible to do?
Thanks.
16 years ago
Could you be more specific what do I need to do in the TableCellRenderer implementation? I can see that this interface has only one method.
What I did is, I created a subclass of the AbstractTableModel class and in that class I overwrote isCellEditable(int row, int column) method as follows:
public boolean isCellEditable(int row, int col) {
boolean result = (row >= 0 && col >= 1 && row != (col - 1));
return result;
}
So this will not allow user to modify cells on the main diagonal. However, these cells look the same as the rest of the cells in the table. I would like to disable them in some obvious and visible way, like when a CheckBox is disabled. Is that possible to do?
Thanks.
16 years ago
I have a table in which main diagonal should be disabled for selection
l s t
l X
s X
t X
Users should be able to click on the remaining cells in order to turn them on or off. I would like to disable the main diagonal so that it is clear to the user that those cannot be changed.
16 years ago
Hi,
here is my problem.
I have a JPanel which contains a JCheckBox which is selected by default.
The panel also contains a JTable. Each cell in the table represents a check box too. By default all cells in the table are selected. I need to deselect the JCheckBox if the user deselects one cell in the table. How can I set up an event listener that would do that?
17 years ago
Hi, I am new to swing and am trying to understand how the new 1.4 focus framework works. Please help.
I have a JPanel that contains 9 components (in order of addition JTextField hours, JTextField minutes, JTextField seconds, JRadioButton countUp, JRadioButton countDown, JButton start, JButton pause, JButton stop, JButton new).
JButtons start, pause, stop and new are not active all the time. For example, buttons pause and stop are not active initially until the start button is pressed, than they become active and start button is deactivated.
The initially focused component in this window is hours. When I tab through the components everything works just fine (I can see that getComponentAfter in my focus traversal policy is being called) until I get to the start button (which is active). The next component should be pause button based on my focus traversal policy, but since it is inactive it is skipped. Moreover, it seems that the getComponentAfter in never even called. Same happens with stop button. The focus is sent to the new button, which is correct but from here on the focus is not sent to the hours field but to the panel itself (again getComponentAfter is not called). All this makes me think that after the inactive buttons were encountered somehow my focus traversal policy is not being used anymore. Can anyone tell me what I am doing wrong?
Here is the code for my focus traversal policy.
class LocalFocusTraversalPolicy extends FocusTraversalPolicy {

private Component[] _components = null;

public LocalFocusTraversalPolicy() {
_components = new Component[9];
_components[0] = durationPN.getHoursTextField();
_components[1] = durationPN.getMinutesTextField();
_components[2] = durationPN.getSecondsTextField();
_components[3] = dynamicTimerPN.countsUpRB;
_components[4] = dynamicTimerPN.countsDownRB;
_components[5] = getButton(1); //Start
_components[6] = getButton(2); //Pause
_components[7] = getButton(3); //Stop
_components[8] = getButton(4); //New

}

public Component getComponentAfter(Container focusCycleRoot,
Component aComponent) {
for (int i=0; i<_components.length; i++) {
if (aComponent == _components[i]) {
int j = (i+1) % _components.length;
return _components[j];
}
}
return null;
}

public Component getComponentBefore(Container focusCycleRoot,
Component aComponent) {
for (int i=0; i<_components.length; i++) {
if (aComponent == _components[i]) {
int j = (i-1+_components.length) % _components.length;
return _components[j];
}
}
return null;
}

public Component getDefaultComponent(Container focusCycleRoot) {
return durationPN.getHoursTextField();
}

public Component getFirstComponent(Container focusCycleRoot) {
return durationPN.getHoursTextField();
}

public Component getInitialComponent(Window window) {
return durationPN.getHoursTextField();
}

public Component getLastComponent(Container focusCycleRoot) {
return getButton(4);
}

}
17 years ago