Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Post Your Vehicle for Sale — FREE! - https://libro.lk
Kalu_Puth
Updated:
21 minutes ago
ඔයාගෙ Assignment හෝ Thesis එක හරියට හදාගමු
ErMurazor
Updated:
Saturday at 10:52 PM
Ad icon
BlackWall V2ray servers
hu KANNA
Updated:
Wednesday at 4:58 AM
Peppa Pig Family Plush Toy Set – 5 Characters
anil1961
Updated:
Sep 19, 2026
Ad icon
Express VPN PC - 1 Year Rs. 600.00
Sanathbh
Updated:
Sep 19, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
React ඉගෙන ගන්නේ
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="MihiCherub" data-source="post: 28862140" data-attributes="member: 238676"><p>මම recently implement කරපු code එකක්</p><p></p><p>--------------------------------------------------------------------------------</p><p></p><p>To add a progress bar to a Java table cell, you can create a custom cell renderer that displays a JProgressBar component instead of a plain text or other data. Here's an example code snippet that demonstrates how to do this:</p><p></p><p>```java</p><p>[CODE=java]public class ProgressBarCellRenderer extends JProgressBar implements TableCellRenderer {</p><p> </p><p> public ProgressBarCellRenderer() {</p><p> setOpaque(true);</p><p> setMinimum(0);</p><p> setMaximum(100);</p><p> }</p><p> </p><p> @Override</p><p> public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {</p><p> if (value instanceof Integer) {</p><p> int progress = (Integer) value;</p><p> setValue(progress);</p><p> setStringPainted(true);</p><p> setString(progress + "%");</p><p> }</p><p> if (isSelected) {</p><p> setBackground(table.getSelectionBackground());</p><p> } else {</p><p> setBackground(table.getBackground());</p><p> }</p><p> return this;</p><p> }</p><p>}[/CODE]</p><p>```</p><p></p><p>This class extends the JProgressBar class and implements the TableCellRenderer interface, which is used to customize the appearance of the cells in a JTable.</p><p></p><p>In the constructor, the progress bar is initialized with a minimum value of 0 and a maximum value of 100.</p><p></p><p>The `getTableCellRendererComponent()` method is called by the JTable to render each cell in the table. In this method, we check if the value of the cell is an integer (which is the expected value for a progress bar). If it is, we set the value of the progress bar to the integer value, and set the progress bar to display the value as a percentage with the `setStringPainted()` and `setString()` methods. If the cell is selected, we set the background color to the selection background color, otherwise, we set it to the default background color.</p><p></p><p>Once you have created this custom cell renderer, you can use it to display progress bars in specific cells of your JTable by setting the cell renderer for that column using the `setCellRenderer()` method. For example, to set the progress bar cell renderer for the 5th column of your JTable, you can use this code:</p><p></p><p>```java</p><p>[CODE=java]JTable table = new JTable();</p><p>table.getColumnModel().getColumn(4).setCellRenderer(new ProgressBarCellRenderer());[/CODE]</p><p>```</p><p></p><p>This code sets the cell renderer for the 5th column of the table to be an instance of the `ProgressBarCellRenderer` class, which will display progress bars in the cells of that column.</p><p></p><p><img src="https://i.imgur.com/DiRIPz4.png" alt="" class="fr-fic fr-dii fr-draggable " style="width: 842px" /></p></blockquote><p></p>
[QUOTE="MihiCherub, post: 28862140, member: 238676"] මම recently implement කරපු code එකක් -------------------------------------------------------------------------------- To add a progress bar to a Java table cell, you can create a custom cell renderer that displays a JProgressBar component instead of a plain text or other data. Here's an example code snippet that demonstrates how to do this: ```java [CODE=java]public class ProgressBarCellRenderer extends JProgressBar implements TableCellRenderer { public ProgressBarCellRenderer() { setOpaque(true); setMinimum(0); setMaximum(100); } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value instanceof Integer) { int progress = (Integer) value; setValue(progress); setStringPainted(true); setString(progress + "%"); } if (isSelected) { setBackground(table.getSelectionBackground()); } else { setBackground(table.getBackground()); } return this; } }[/CODE] ``` This class extends the JProgressBar class and implements the TableCellRenderer interface, which is used to customize the appearance of the cells in a JTable. In the constructor, the progress bar is initialized with a minimum value of 0 and a maximum value of 100. The `getTableCellRendererComponent()` method is called by the JTable to render each cell in the table. In this method, we check if the value of the cell is an integer (which is the expected value for a progress bar). If it is, we set the value of the progress bar to the integer value, and set the progress bar to display the value as a percentage with the `setStringPainted()` and `setString()` methods. If the cell is selected, we set the background color to the selection background color, otherwise, we set it to the default background color. Once you have created this custom cell renderer, you can use it to display progress bars in specific cells of your JTable by setting the cell renderer for that column using the `setCellRenderer()` method. For example, to set the progress bar cell renderer for the 5th column of your JTable, you can use this code: ```java [CODE=java]JTable table = new JTable(); table.getColumnModel().getColumn(4).setCellRenderer(new ProgressBarCellRenderer());[/CODE] ``` This code sets the cell renderer for the 5th column of the table to be an instance of the `ProgressBarCellRenderer` class, which will display progress bars in the cells of that column. [IMG width="842px"]https://i.imgur.com/DiRIPz4.png[/IMG] [/QUOTE]
Insert quotes…
Verification
Awruddata maasa keeyada?
Post reply
Top
Bottom