Swing/AWT/SWT :: Fill JTable From Database With SwingWorker?

Sep 26, 2014

Why this code is not working/my JTable won't updated after i click the button

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;

[code]....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Refreshing JTable From Database

May 21, 2014

I want to add a Refresh button to my frame to refresh the data from the database, but I'm not sure how to refresh the data in the jtable. The constructor below initially creates the table and displays the data. Should my button destroy/create the JPanel all over, or is there a single method within the TableModel that will redisplay the data?

class TablePanel extends JPanel {
private Connection con;
private JTable table;
TablePanel() {
try {

[code].....

View Replies View Related

Swing/AWT/SWT :: Using Multiple SwingWorker Threads

Aug 23, 2014

I have a Swing UI in which on click of Search button, I trigger the Search in 6 different modules in 6 Swing Worker threads. The results are returned by each Swing Worker class to the calling class.

I tried to use the below code to get the values returned from each thread. Now, I want to continue further only after all threads finish their execution. How to achieve this?

thread1.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (StateValue.DONE == thread1.getState()) {
try {

[Code] ....

I got several examples where the UI is updated direstly from multiple threads. I want the values to be returned to calling class because of below reasons:

1) When even one worker thread fails for some reason, I dont want to show the any result in the UI
2) Earlier, I was updating the UI in done() of every worker class. But, UI became inconsistent. E.g When one thread is in progress, other threads were completed and updating the UI which I dont want to do.

View Replies View Related

Swing/AWT/SWT :: Add / Edit And Delete JTable With Database

Apr 2, 2015

I currently have all the code working to fill my database and to display it, although I would like to have it displaying in a JPanel but I cannot figure it out so a JFrame will do. Add, Edit and Delete button for the JTable so I can add rows to the table and database, edit existing rows and delete rows also.

Here is the code for my current class.

package ManGUI;
import Database.DatabaseOperations;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;
import javax.xml.crypto.Data;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Do GUI Input Processing After Firing Off SwingWorker

Oct 8, 2014

I am writing a program that solves sudoku puzzles. It has a Swing GUI with a "solve" button. I have written an actionListener class with an actionPerformed method that is invoked when the user presses this button. It is the following:

public void actionPerformed(ActionEvent event) {
try {
worker = new SudokuSolveWorker();
worker.addPropertyChangeListener(this);
worker.execute();
SolveFrame sf = new SolveFrame();
} catch (Exception exc) {
System.out.println(exc.getMessage());
exc.printStackTrace();
}
}

The code creates a worker, a new instance of SudokuSolveWorker. The worker.execute() statement causes the doInBackground() method of this class to be called. This solves the Sudoku. A property change listener "picks up" the result:

public void propertyChange(PropertyChangeEvent event) {
try {
System.out.println("" + javax.swing.SwingUtilities.isEventDispatchThread());
SudokuModel solvedModel = (SudokuModel) worker.get();
} catch (Exception exc) {
System.out.println(exc.getMessage());
exc.printStackTrace();
}
}

As I wrote, this works without freezing up the user interface in the sense that the program seems unstable. However, the user interface does not respond to "commands" (mouse clicks) anymore until the worker thread has finished.

In the first code fragment I create an instance of SolveFrame which is an extension of a JFrame. It is a simple frame with a "cancel" button. It is drawn on the screen, even though it is called after the worker.execute() statement. I'd like the user to be able to click this "cancel" button, after which the solving of the sudoku puzzle should be stopped. However, since the program does not respond to mouse clicks anymore, the "cancel" button cannot be pressed.

View Replies View Related

How To Fill Contents To Jtable Dynamically On Button Click

Dec 17, 2014

this is my code

private void showresultsActionPerformed(java.awt.event.ActionEv ent evt) {
Object dbs=db.getSelectedItem();
Object colls=coll.getSelectedItem();
String distances=distance.getText();
String skillss=skills.getText();
DefaultTableModel tb=new DefaultTableModel();
MongoClient m = null;

[Code]...

i have added the columns but how could i show up the change??

View Replies View Related

Swing/AWT/SWT :: How To Fill Text Fields With Selection From JList

May 2, 2015

I have an addressBook GUI where I have a JList that populates with the contacts names, and once I double click a contacts name I'm wanting to fill the textfields with the contacts corresponding data.

ex) ContactType: Family (enum), Name: Zoidberg, Address: 111 Space Drive, City: New York City, etc...

I've got it to where I select open from the JMenu, it populates the JList, but once I select a contacts name, all the textfields are populated, but only with the contacts name

ex) Name: Zoidberg, Address: Zoidberg, City: Zoidberg, etc....

What am i doing wrong here, and how can i fix it to where it fills out the correct data?

Here's my code so far:

public class AddressBookGUI extends JFrame {
private final int WIDTH = 450;
private final int HEIGHT = 300;
private JLabel currentlySelected;
private JTextField contactTypeTextField;

[code]...

I'm certain the logic is messed up near the end where i set all text fields to the index, because no matter what field i want to fill it's at it's going to set it to whatever index I select, but I don't know how to fix it.

View Replies View Related

JTable Filled From Database

Oct 9, 2014

Im building a program that tracks overtime for employees. Basically there will be a list of employees. Number will be dynamic as different departments will have different amounts of employees.A user could pick the department from a JCombobox. E.g Quality Control. A Jtable will be populated with the employees from Quality Control.

The problem is this.

The way it will work is the list will be in a specific order. Whoever is at the top of the list will be asked if they want to do overtime. Then they will be moved to the back of the queue. If they do the work or not doesnt matter.How would i go about planning a system like this? Specifically creating a dynamic list that people can be moved up and down and stored persistently. URL...

View Replies View Related

Multiple Rows Into Database From JTable

Apr 12, 2014

How to insert multiple rows into a database from a jtable and also retrive the same details from database and show it in a jtable.

View Replies View Related

Auto Updating JTable From Database

Feb 10, 2015

I'm doing an application which needs a JTable with data from an existing database. I need the table to periodically (I plan to use a Timer) reflect the changes made to the DB (inserting new rows, deleting or updating existing rows) without making the dirty approach of clearing the whole JTable and refilling it again, which is not nice. I need to just add/modify/delete the needed rows, not the whole table.

View Replies View Related

Saving Edited Data From JTable Into Database?

Jul 16, 2014

The Table Model

package presentation;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import business.*;
public class BgTableModel extends AbstractTableModel

[code]....

View Replies View Related

Saving Edited Data From JTable Into Database

Jul 16, 2014

I've tried everything but in vain..I want to save the data from the table into the database, I can easily connect to the database. All I want is how to get the values from the table. I've tried this method to get the values but its not working because of the contructor error in the BgTableModel class.

Tried Method
public void writeBgEdu() {
int last=gtm.getRowCount();
System.out.println(last);
for( int i=0;i<last;i++) {
if(((String) gtm.getValueAt(i,0))!=null)

[Code] .....

View Replies View Related

Unable To Get Values From JTable And Insert Them In MySQL Database

Feb 7, 2014

i have a problem, im trying to get some values from a jtable (tabla) and insert them in a mysql database, so i scan the table for some values to know which of the rows i must insert ("s" or "n").

I'm able to insert few rows, but when the last row with "s" or "n" is inserted it launch me a NullPointerException and I dont know why.

public void insertar(JTable tabla, int rowt, int colt) throws ParseException{
String documento=null, cve_clie=null, fechaE=null, fechaR=null, check=null;
char d=' ',dd=' ',m=' ',mm=' ',y1=' ',y2=' ',y3=' ',y4=' ';
String chck = null;
try{
conexion = connMysql.mysql();
String squery="insert into consefact3 values (?,?,?,?,?)";
PreparedStatement pst = conexion.prepareStatement(squery);

[Code]...

View Replies View Related

Swing/AWT/SWT :: JTable With Fixed Row

Nov 9, 2008

My JTable has a row, row number 0, which I always want to be at the top.I tried the following two approaches, both without success:

1- Use a custom table cell renderer for the header, and create a header of two rows. the second row is my JTextField.

Problem: I cannot get the JTextField to function properly. (I've seen examples with a checkbox in the header, but that one just reacts to a click somewhere on the header, my textfield must be editable).

2- Use the first row of the table. This works quite nice. However, I must prevent row 0 to be re-ordered when sorting the table.

I was thinking to add a prefix (either something like "___" or "zzz" depending on current sorting mode), but I do not know which methods to adjust for this exaclty.

Another approach would be to have N textfields above the JTable in some layout (or two JTable's on top of each other).

However, Then I would need to react to the re-ordering and re-sizing of all columns as well, which does not seem easy to me.

View Replies View Related

Swing/AWT/SWT :: Using JList Instead Of JTable?

Apr 18, 2014

Can I use Jlist instead of Jtable for showing database table data (select * from employee) in my code?

View Replies View Related

Swing/AWT/SWT :: Can't Select The Very Last Row In A Jtable

Mar 26, 2015

I have encountered a very tricky spot in a project that i am working on. I must have a JTable to programmatically select the very last row in an AbstractTableModel. I have tried every thing but nothing works so far.

The problem is is that the JTable only scrolls down to the second last table row in the model? What am i missing?

//Show the very last row in a tablemodel object using the method updateTableRows
//after an "insert action event" occurred
public void updateViewMode(String name,
java.util.List<NetworkSwitch> list,
boolean flag) {
CableTableModel model = cableTable.getCableModel();

[code]....

What happens is that the only row that gets selected is the second last row of the total rows iny AbstractTableModel object, "CableTableModel"

What am i missing?

View Replies View Related

Swing/AWT/SWT :: JTable Not Getting Updated

Nov 17, 2014

I am preparing a small solution. Below is how the functionality works.

1. Login Screen
2. Successful Login will take to a MDI Form
3. Click the menu, a JInternalFrame will open in the JDestopPane.
4. JInternalFrame has a JTable.
5. JInternalFrame has a JButton available for adding new data.
6. When JButton is clicked, a new JInternalFrame is popped up with some JTextField and JButton to save the data.
7. After saving the data (after insert query), a JDialog is opened to upload Logo (update query for BLOB), There are two buttons in the JDialog, one is for uploading the image, another one is uploading it later.
8. The logo is displayed in the JDialog and if the JButton, for upload is pressed, update the database and reload the JTable in the JInternalFrame is called.

My challenge is in point 8. The function is called properly, but the table is not getting refreshed.

JButton in JDialog for uploading the Logo
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(this, "Image Uploaded Successfully");
companyConfig cc = new companyConfig();
//cc.reloadTable();
cc.updateTable();
this.dispose();

[code]....

View Replies View Related

Swing/AWT/SWT :: JTable Sum Of A Column

Feb 9, 2015

I've been creating a jTable where I can add / edit /delete new entries. Now i have 2 Questions :

1) My column 0 is filled with the row-number. I created a variable and with each "add" it adds +1 to the variable. That works, but as soon as i delete 1 row there is a gap ( 1..2..4..5..).

My question: Is there another way then mine to handle this?

2) The table is/should be working as some kind of database. The user is able to add Information (height, width,...). Now I want to sum the entries of 1 column (length,...). But as they´re objects I didn´t find a way.

My question: How can I sum the entries of 1 column of a table?

View Replies View Related

Swing/AWT/SWT :: JTable Instead Of JTextArea

May 3, 2015

i have this code when i selected a node it display the attribut and value of it in JTextArea but i want it into table :

public void valueChanged( TreeSelectionEvent event )
{
if( event.getSource() == jtree ){
{
FramePrincipale.getExplorePanelll().setText(null);
TreePath path = jtree.getSelectionPath();
String a = changeString(path);
Hashtable env1 = System.getProperties();
env1.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env1.put(Context.PROVIDER_URL, "ldap://localhost:11389/");

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Get Data From JTextField Over To JTable

Jun 20, 2014

I am trying to get the data entered in a JTextField into a JTable but not clear on how. The LeftPanel is where the button is located and the RightPanel is where the JTable is. I want the actionPerformed to update the row of the JTable but I can't figure out how. There is another class that controls the GUI but did not think it was necessary to include. Also, I am aware that I am getting an error at the addRow line, can't seem to alleviate it.

public class LeftPanel extends JPanel {

private static final long serialVersionUID = -2311952438693382407L;
private RightPanel rPanel;
public LeftPanel(){
Dimension size = getPreferredSize();
size.width = 250;
setPreferredSize(size);

[code]....

View Replies View Related

Swing/AWT/SWT :: Getting A Row Of Names From The First Column Of JTable?

Feb 9, 2014

I have a JTable with the model " Names " , " Quantity " and " Unit " .

I'm coding a program where you get the ingredients names.

So i need to get the whole row of one column and String it all up together,because i need to store it in mySql and i have already set it all as String.

how i can do this ?

My code are as follows :

JTable Code:

DefaultTableModel model = (DefaultTableModel)table.getModel();
if(!txtQty.getText().trim().equals("")){
model.addRow(new Object[]{ingCB.getSelectedItem().toString(),txtQty.getText(),unitCB.getSelectedItem().toString()});
}else{
JOptionPane.showMessageDialog(null,"*Quantity field left blank");
}

Getting the values and for storing :

for(int i = 1; i<= i ; i++){
ingredients = table.getName();
}

This is for loop is wrong and it does not work because i have a constructor to take in Ingredients but because it is inside the loop, it cannot take it in.

View Replies View Related

Swing/AWT/SWT :: How To Make A Row Of JTable Not Editable

Feb 8, 2014

When I click on a row in a JTable, I want to have a row appear above it. For now I'm just making that row be a duplicate of the row I clicked on, but eventually this will be some sort of previous history of that row, so as you are editing the row you actually clicked on you can look directly above it and see what the data used to look like.

I"m not having any problem creating the row, nor am I having an issue getting it positioned correctly. What I want to do with this added row is made it so you can't edit the entire row, and also really make this row stand out. I'd like to say make this row stand out or "POP" so to speak so there is no confusing what it is. I'd almost like to make it look like the row header or even better... Most of what I am seeing are ways to make particular cells uneditable, so I think my backup plan is that, but Is there a good way to do what I described?

View Replies View Related

Swing/AWT/SWT :: SQL Server Table In JTable

May 29, 2014

I am attempting to show a GUI that will show records from a SQL Server table. That part I have done. However, I need to allow the user to be able to edit the Approval field of the table when he/she views it. Following is my code:

package manual_checks;

import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.TableColumn;
import java.awt.Font;
import javax.swing.event.ListSelectionListener;

[code]....

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 :: Finding Strings In A JTable

Jan 31, 2015

I am having a problem finding string objects in a jTable. I use setValueAt() to write string variables into a jTable.

I can then use getValueAt() to search to find any of those strings. All works fine until I edit an entry in the table. Then I can never find that string again.

In fact, if I just click in the cell type a character, then delete that character, something changes. The contents of the cell look the same but the search for it doesn't find it.

For example if I have a string "xyz" that was written in a cell. If I set the search value, "a=xyz", and "b=getValueAt(some cell)".

Then at the compare:

if(a==b) I can hover over a and b and I see that;
a = (java.lang.String) xyz

and

b = (java.lang.String) xyz

[note I am using NetBeans to do this]

after the compare, the true path is taken .

If I then click in the cell then click out and try the same compare, everything is exactly the same including what gets reported when I hover. But the false path is taken at the "if".

View Replies View Related

Swing/AWT/SWT :: How To Remove Jtable Border

Apr 26, 2015

How can I remove the light blue border? I tried everything that I know [URL]

View Replies View Related







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