473,785 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help to solve flickering Checkbox in JTable

Hi all,
I have a problem with a Checkbox in a JTable.
When i add the Checkbox into the JTable it displays the String
representation of the Checkbox, which is not what i want.
So, i created a CheckBoxRendere r which extens Checkbox and implements
TableCellRender er. This seems to have done the job, in that the Checkbox
is displayed and not the String representation. But, and it's a big
'but', the column that holds the Checkbox continually updates the
fields. I cannot select the Checkbox and i can only just see that the
correct info for the Checkbox is in the cell.
I think it has something to do with repainting the Checkbox, but i can't
figure out how to stop it from happening.

Many thanx.
Ben

Here is some of the code, the bit's i think are relevent:
All code is at:
http://www.users.on.net/benmunday/Label/

public class CheckBoxRendere r extends Checkbox implements TableCellRender er
{

....

public Component getTableCellRen dererComponent( JTable table, Object
cBox, boolean isSelected, boolean hasFocus, int row, int column)
{
Checkbox newCheckbox = (Checkbox)cBox;
newCheckbox.set State(false);
return newCheckbox;
}
}

JTable itemDataTable = new JTable(new MyTableModel(da ta));
itemDataTable.s etDefaultRender er(data[0][0].getClass(),
new CheckBoxRendere r());

itemDataScrollP ane.getViewport ().setView(item DataTable);
itemDataScrollP ane.setVisible( true);

contentPane.add (itemDataScroll Pane, BorderLayout.CE NTER);

Jul 17 '05 #1
1 8635
Ben Munday <be******@hotma il.com> wrote in message news:<40******* *@duster.adelai de.on.net>...
http://www.users.on.net/benmunday/Label/ This URL is invalid.
public Component getTableCellRen dererComponent( JTable table, Object
cBox, boolean isSelected, boolean hasFocus, int row, int column)
{
Checkbox newCheckbox = (Checkbox)cBox;
newCheckbox.set State(false);
return newCheckbox;


I believe you better install conditionals upon isSelected and
hasFocus in the method. Another thing is that JComponent uses
double buffering by default so I believe you should use JCheckBox
instead of awt.CheckBox. In general, mixing use of the awt
component and Swing component is not a good, let alone best,
practice.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1443
by: asd | last post by:
I need to modify any given column's header in my JTable. I couldn't find a way of doing this, so I attempted to remove the necessary TableColumn and re-add a TableColumn into the same position. The problem I'm having is that it adds the TableColumn to the end of the JTable, even when I set the appropriate index in the TableColumn constructor. I've tried adding the TableColumn to the JTable and its DefaultTableModel, neither works. Here...
1
8975
by: asd | last post by:
I need to make the cells in the 1st column look like the column header. I tried the following code but it didn't change anything: private void rendererTest() { TableColumn column = tblDecisions.getColumnModel().getColumn(0); TableCellRenderer renderer = column.getHeaderRenderer(); column.setCellRenderer(renderer); }
1
1477
by: viator | last post by:
Hello Everybody, This might be a dumb question, but I need help. Is there a way to add and remove rows/columns dynamically at runtime from a JTable.
0
3147
by: sivaprasad06 | last post by:
Hi, I have a editable combo box editor as a cell editor for JTable. I want use only key board to enter data into jtable. so i am using ALT+Down comobination for making cell editiable in the jtable. when user clicks that combination what ever editor present in that cell will appear. I am using tab for traversing all cells in table.
0
3398
by: nuria | last post by:
hi, I have an editable JTable, when you are editing it and press F8 shows a dialog and then go again to the JTable window but the focus goes to a JtextField component, go with the tab for the rest of the textfields and when have to get the focus again the JTable can´t get it !!! only if I go with the mouse!!!! I am trying all things, give the focus to other component before call the Jdialog, put visible(false) the JTable before call...
1
6745
by: Andrea Sansottera | last post by:
Hi fellows, I was wondering if in the Java API there's a way to easily map a disconnected RowSet to a JTable... I have looked at the doc but i did not found anything. What I want is simply do the follow: 1. Load: Database -> disconected Rowset -> automapping in a JTable 2. Editing of the data in the table/rowset
1
1728
by: Salha | last post by:
Hello There, I have two question about the JTable in Java: 1. How can i fix the column width? I want to have one column widder than the other and not editable at runtime. 2. How can i have multiple lines (block of data/small paragraph) in one cell? because whenver i write a 3 lines of data in a cell the JTable converts it cont. line. Please Help!!
5
9852
by: moizpalitanawala | last post by:
Hello friends, How to add data to JTable from a .txt file. I had seen this code from one of the tutorial from java.com. This code doesnt take any input. But shows what is written in the array. But i want the table to display the data from a .txt file in which i had stored information in this format. Can anyone please modify the codes and explain me. Name:Mr.xyz Phone:111111222222
2
3767
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error when i do the following. if you add a contact with up to 13 fields it will be stored in a data structure. i have a tabbed pane that will show six of the 13 fields for that contact. when you double click the contact i want it to pop up and show all 13...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.