SlideShare a Scribd company logo
1 of 10
Download to read offline
How do I make my JTable non editable?
import java.awt.*;
import javax.swing.table.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.nio.*;
import java.nio.charset.Charset;
import java.nio.file.*;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
public class SwingDemo implements ActionListener, KeyListener
{
JLabel search, output;
JFrame viewer;
JTable table = new JTable(new DefaultTableModel(null, new Object []{"Row ID", "First
Name", "Last Name", "EMPLID", "GPA", "Venus Login"}));
JFrame viewerAdd;
DefaultTableModel model = (DefaultTableModel) table.getModel();
JTextField first = new JTextField(20);
JTextField last = new JTextField(20);
JTextField emplid = new JTextField(20);
JTextField gpa = new JTextField(20);
JTextField venus = new JTextField(10);
String Venus;
public static int rowCount = 1;
public final static int LOAD = 0;
public final static int SAVE = 1;
public SwingDemo()
{
//Creates Java Frame
viewer = new JFrame("Final Project");
viewer.setSize(570, 650);
viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
viewer.setLayout(new FlowLayout());
viewer.setLocationRelativeTo(viewer);
//Creates Drop Down Menu
String[] option = { "Row ID", "First Name", "Last Name", "EMPLID", "GPA", "Venus
Login" };
JComboBox options = new JComboBox(option);
options.setSelectedIndex(0);
//Creates Button and Labels
search = new JLabel("Search by: ");
JButton addButton = new JButton("Add");
JButton deleteButton = new JButton("Delete");
JButton exportButton = new JButton("Export Data");
//Creates JTable
JTextField textBox = new JTextField(20);
table = new JTable(model);
JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);
//Creates Menu Bar
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenu helpMenu = new JMenu("Help");
menuBar.add(fileMenu);
menuBar.add(helpMenu);
JMenuItem openAction = new JMenuItem("Open");
JMenuItem exitAction = new JMenuItem("Exit");
JMenuItem exportAction = new JMenuItem("Export");
JMenuItem aboutAction = new JMenuItem("About");
fileMenu.add(openAction);
fileMenu.add(exportAction);
fileMenu.add(exitAction);
helpMenu.add(aboutAction);
//fileChooser.setDialogTitle("Choose a file");
//ActionListener
openAction.addActionListener(this);
exitAction.addActionListener(this);
aboutAction.addActionListener(this);
addButton.addActionListener(this);
//Action Events
//Adds Elements to Java Frame
viewer.setJMenuBar(menuBar);
viewer.add(search);
viewer.add(options);
viewer.add(textBox);
viewer.add(addButton);
viewer.add(deleteButton);
viewer.add(scrollPane);
viewer.add(exportButton);
viewer.setVisible(true);
}
public void addUser()
{
JButton OK = new JButton("OK");
JButton CANCEL = new JButton("CANCEL");
//JTextField
//Strings
JLabel firstName = new JLabel("First Name");
JLabel lastName = new JLabel("Last Name");
JLabel EMPLID = new JLabel("EMPLID");
JLabel GPA = new JLabel("GPA");
JLabel venusLogin = new JLabel("Venus Login");
//ActionListener
first.addActionListener(this);
last.addActionListener(this);
emplid.addActionListener(this);
gpa.addActionListener(this);
first.addKeyListener(this);
last.addKeyListener(this);
emplid.addKeyListener(this);
viewerAdd = new JFrame("Add User");
viewerAdd.setSize(300, 200);
viewerAdd.setDefaultCloseOperation(viewerAdd.HIDE_ON_CLOSE);
viewerAdd.setLayout(new GridLayout(6,2));
viewerAdd.setLocationRelativeTo(viewerAdd);
viewerAdd.add(firstName);
viewerAdd.add(first);
viewerAdd.add(lastName);
viewerAdd.add(last);
viewerAdd.add(EMPLID);
viewerAdd.add(emplid);
viewerAdd.add(GPA);
viewerAdd.add(gpa);
viewerAdd.add(venusLogin);
viewerAdd.add(venus);
viewerAdd.add(OK);
viewerAdd.add(CANCEL);
OK.addActionListener(this);
CANCEL.addActionListener(this);
venus.setEditable(false);
viewerAdd.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) throws NumberFormatException
{
switch(e.getActionCommand())
{
case "Exit":
System.exit(0);
break;
case "Open":
FileDialog fileChooser = new FileDialog(viewerAdd,"Select file",FileDialog.LOAD);
fileChooser.setVisible(true);
JFileChooser a = new JFileChooser(fileChooser.getFile());
File[] file;
file = fileChooser.getFiles();
if(fileChooser.getFile() != null)
{
try
{
BufferedReader br = new BufferedReader(new FileReader(file[0]));
String line;
while ((line = br.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line, "," +" ");
String f = st.nextToken();
String l = st.nextToken();
String em = st.nextToken();
String g = st.nextToken();
String v = st.nextToken();
model.addRow(new Object[]{rowCount++,f, l, em, g, v});
}
}
catch (FileNotFoundException ex)
{
System.out.println("o");
}
catch (IOException e1)
{
JOptionPane.showMessageDialog(fileChooser, "There was an IO Exception that was
caught. Error: "+ e1.getMessage(), null, JOptionPane.ERROR_MESSAGE);
e1.printStackTrace();
}
}
else
{
JOptionPane.showMessageDialog(null, "File Not Selected", null,
JOptionPane.ERROR_MESSAGE);
}
break;
case "About":
JOptionPane.showMessageDialog(viewer, "This is an App made by ");
break;
case "Add":
addUser();
break;
case "OK":
int userAction1 = JOptionPane.showConfirmDialog(null, "Are You Sure You Want To Insert
this Record?");
int number;
double number1;
boolean emp, ga = false;
if(userAction1 == JOptionPane.YES_OPTION)
{
String firstName = first.getText();
String lastName = last.getText();
String Emplid = emplid.getText();
String Gpa = gpa.getText();
if (firstName.length() < 2)
JOptionPane.showMessageDialog(null, "First Name must contain at least 2 characters",
null, JOptionPane.ERROR_MESSAGE);
else if (lastName.length() < 2)
JOptionPane.showMessageDialog(null, "Last Name must contain at least 2 characters",
null, JOptionPane.ERROR_MESSAGE);
else if (Emplid.length()!=8)
JOptionPane.showMessageDialog(null, "EMPLID must contain 8 numbers", null,
JOptionPane.ERROR_MESSAGE);
try
{
number = Integer.parseInt(Emplid);
try
{
number1 = Double.parseDouble(Gpa);
if(number1 < 0 || number1 > 4)
JOptionPane.showMessageDialog(null, "GPA must be between 0.0 - 4.0", null,
JOptionPane.ERROR_MESSAGE);
else
ga = true;
}
catch (Exception s)
{
JOptionPane.showMessageDialog(null, "GPA must be between 0.0 - 4.0", null,
JOptionPane.ERROR_MESSAGE);
}
}
catch (Exception s)
{
JOptionPane.showMessageDialog(null, "EMPLID must contain 8 numbers only", null,
JOptionPane.ERROR_MESSAGE);
}
if (ga == true)
{
model.addRow(new Object[]{rowCount++,firstName, lastName, Emplid, Gpa, Venus});
viewerAdd.setVisible(false);
first = new JTextField(20);
last = new JTextField(20);
emplid = new JTextField(20);
gpa = new JTextField(20);
venus = new JTextField(10);
}
}
break;
case "CANCEL":
viewerAdd.setVisible(false);
break;
}
}
@Override
public void keyTyped(KeyEvent e)
{
try
{
venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub
string(4,8));
}
catch(Exception s)
{
}
Venus = venus.getText();
}
@Override
public void keyPressed(KeyEvent e)
{
try
{
venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub
string(4,8));
}
catch(Exception s)
{
}
Venus = venus.getText();
}
@Override
public void keyReleased(KeyEvent e)
{
try
{
venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub
string(4,8));
}
catch(Exception s)
{
}
Venus = venus.getText();
}
}
Solution
step 1:Go to the Navigation Pane, expand JScrollPane option
step 2:In JSCROLLPne, right-click on JTable and Select Customize Code as shown below:
step 3:On the code customizer option, choose custom property in the second drop down
step 4: Insert the code written below ,before the last bracket);code is given below
step5:{public boolean isCellEditable(int row, int column){return false;}}

More Related Content

Similar to How do I make my JTable non editableimport java.awt.; import j.pdf

I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdffashionfolionr
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdffathimaoptical
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfanushkaent7
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfamrishinda
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfJUSTSTYLISH3B2MOHALI
 
Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfarvindarora20042013
 
Registro de venta
Registro de ventaRegistro de venta
Registro de ventalupe ga
 
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfvenkt12345
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Kuldeep Jain
 
Ejemplo radio
Ejemplo radioEjemplo radio
Ejemplo radiolupe ga
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxwhitneyleman54422
 
import javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdfimport javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdfADITIEYEWEAR
 
Soundreader.classpathSoundreader.project Soundre.docx
Soundreader.classpathSoundreader.project  Soundre.docxSoundreader.classpathSoundreader.project  Soundre.docx
Soundreader.classpathSoundreader.project Soundre.docxwhitneyleman54422
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfatulkapoor33
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 

Similar to How do I make my JTable non editableimport java.awt.; import j.pdf (20)

I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdf
 
Notepad
NotepadNotepad
Notepad
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdf
 
Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdf
 
Registro de venta
Registro de ventaRegistro de venta
Registro de venta
 
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Easy Button
Easy ButtonEasy Button
Easy Button
 
Ejemplo radio
Ejemplo radioEjemplo radio
Ejemplo radio
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
import javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdfimport javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdf
 
Java Assignment Help
Java Assignment HelpJava Assignment Help
Java Assignment Help
 
Maze
MazeMaze
Maze
 
Soundreader.classpathSoundreader.project Soundre.docx
Soundreader.classpathSoundreader.project  Soundre.docxSoundreader.classpathSoundreader.project  Soundre.docx
Soundreader.classpathSoundreader.project Soundre.docx
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdf
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 

More from forwardcom41

Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfHello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfforwardcom41
 
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfHey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfforwardcom41
 
Given technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfGiven technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfforwardcom41
 
Explain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfExplain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfforwardcom41
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfforwardcom41
 
Complete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfComplete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfforwardcom41
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfforwardcom41
 
Describe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfDescribe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfforwardcom41
 
Why is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfWhy is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfforwardcom41
 
What are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfWhat are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfforwardcom41
 
What is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfWhat is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfforwardcom41
 
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfw Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfforwardcom41
 
Which of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfWhich of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfforwardcom41
 
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfUsing the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfforwardcom41
 
why we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfwhy we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfforwardcom41
 
What property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfWhat property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfforwardcom41
 
What is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfWhat is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfforwardcom41
 
What is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfWhat is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfforwardcom41
 
What are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfWhat are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfforwardcom41
 
Use the following information to answer the next Question. The graph.pdf
Use the following information to answer the next Question.  The graph.pdfUse the following information to answer the next Question.  The graph.pdf
Use the following information to answer the next Question. The graph.pdfforwardcom41
 

More from forwardcom41 (20)

Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfHello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
 
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfHey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
 
Given technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfGiven technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdf
 
Explain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfExplain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdf
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
 
Complete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfComplete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdf
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 
Describe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfDescribe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdf
 
Why is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfWhy is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdf
 
What are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfWhat are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdf
 
What is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfWhat is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdf
 
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfw Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
 
Which of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfWhich of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdf
 
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfUsing the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
 
why we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfwhy we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdf
 
What property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfWhat property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdf
 
What is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfWhat is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdf
 
What is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfWhat is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdf
 
What are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfWhat are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdf
 
Use the following information to answer the next Question. The graph.pdf
Use the following information to answer the next Question.  The graph.pdfUse the following information to answer the next Question.  The graph.pdf
Use the following information to answer the next Question. The graph.pdf
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

How do I make my JTable non editableimport java.awt.; import j.pdf

  • 1. How do I make my JTable non editable? import java.awt.*; import javax.swing.table.*; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableModel; import java.awt.event.*; import java.io.*; import javax.swing.*; import java.nio.*; import java.nio.charset.Charset; import java.nio.file.*; import java.awt.Desktop; import java.io.File; import java.io.IOException; import java.util.Scanner; import java.util.StringTokenizer; public class SwingDemo implements ActionListener, KeyListener { JLabel search, output; JFrame viewer; JTable table = new JTable(new DefaultTableModel(null, new Object []{"Row ID", "First Name", "Last Name", "EMPLID", "GPA", "Venus Login"})); JFrame viewerAdd; DefaultTableModel model = (DefaultTableModel) table.getModel(); JTextField first = new JTextField(20); JTextField last = new JTextField(20); JTextField emplid = new JTextField(20); JTextField gpa = new JTextField(20); JTextField venus = new JTextField(10); String Venus; public static int rowCount = 1; public final static int LOAD = 0;
  • 2. public final static int SAVE = 1; public SwingDemo() { //Creates Java Frame viewer = new JFrame("Final Project"); viewer.setSize(570, 650); viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); viewer.setLayout(new FlowLayout()); viewer.setLocationRelativeTo(viewer); //Creates Drop Down Menu String[] option = { "Row ID", "First Name", "Last Name", "EMPLID", "GPA", "Venus Login" }; JComboBox options = new JComboBox(option); options.setSelectedIndex(0); //Creates Button and Labels search = new JLabel("Search by: "); JButton addButton = new JButton("Add"); JButton deleteButton = new JButton("Delete"); JButton exportButton = new JButton("Export Data"); //Creates JTable JTextField textBox = new JTextField(20); table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); //Creates Menu Bar JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu helpMenu = new JMenu("Help"); menuBar.add(fileMenu); menuBar.add(helpMenu);
  • 3. JMenuItem openAction = new JMenuItem("Open"); JMenuItem exitAction = new JMenuItem("Exit"); JMenuItem exportAction = new JMenuItem("Export"); JMenuItem aboutAction = new JMenuItem("About"); fileMenu.add(openAction); fileMenu.add(exportAction); fileMenu.add(exitAction); helpMenu.add(aboutAction); //fileChooser.setDialogTitle("Choose a file"); //ActionListener openAction.addActionListener(this); exitAction.addActionListener(this); aboutAction.addActionListener(this); addButton.addActionListener(this); //Action Events //Adds Elements to Java Frame viewer.setJMenuBar(menuBar); viewer.add(search); viewer.add(options); viewer.add(textBox); viewer.add(addButton); viewer.add(deleteButton); viewer.add(scrollPane); viewer.add(exportButton); viewer.setVisible(true); } public void addUser() { JButton OK = new JButton("OK"); JButton CANCEL = new JButton("CANCEL"); //JTextField
  • 4. //Strings JLabel firstName = new JLabel("First Name"); JLabel lastName = new JLabel("Last Name"); JLabel EMPLID = new JLabel("EMPLID"); JLabel GPA = new JLabel("GPA"); JLabel venusLogin = new JLabel("Venus Login"); //ActionListener first.addActionListener(this); last.addActionListener(this); emplid.addActionListener(this); gpa.addActionListener(this); first.addKeyListener(this); last.addKeyListener(this); emplid.addKeyListener(this); viewerAdd = new JFrame("Add User"); viewerAdd.setSize(300, 200); viewerAdd.setDefaultCloseOperation(viewerAdd.HIDE_ON_CLOSE); viewerAdd.setLayout(new GridLayout(6,2)); viewerAdd.setLocationRelativeTo(viewerAdd); viewerAdd.add(firstName); viewerAdd.add(first); viewerAdd.add(lastName); viewerAdd.add(last); viewerAdd.add(EMPLID); viewerAdd.add(emplid); viewerAdd.add(GPA); viewerAdd.add(gpa); viewerAdd.add(venusLogin); viewerAdd.add(venus); viewerAdd.add(OK); viewerAdd.add(CANCEL); OK.addActionListener(this); CANCEL.addActionListener(this);
  • 5. venus.setEditable(false); viewerAdd.setVisible(true); } @Override public void actionPerformed(ActionEvent e) throws NumberFormatException { switch(e.getActionCommand()) { case "Exit": System.exit(0); break; case "Open": FileDialog fileChooser = new FileDialog(viewerAdd,"Select file",FileDialog.LOAD); fileChooser.setVisible(true); JFileChooser a = new JFileChooser(fileChooser.getFile()); File[] file; file = fileChooser.getFiles(); if(fileChooser.getFile() != null) { try { BufferedReader br = new BufferedReader(new FileReader(file[0])); String line; while ((line = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(line, "," +" "); String f = st.nextToken(); String l = st.nextToken(); String em = st.nextToken();
  • 6. String g = st.nextToken(); String v = st.nextToken(); model.addRow(new Object[]{rowCount++,f, l, em, g, v}); } } catch (FileNotFoundException ex) { System.out.println("o"); } catch (IOException e1) { JOptionPane.showMessageDialog(fileChooser, "There was an IO Exception that was caught. Error: "+ e1.getMessage(), null, JOptionPane.ERROR_MESSAGE); e1.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "File Not Selected", null, JOptionPane.ERROR_MESSAGE); } break; case "About": JOptionPane.showMessageDialog(viewer, "This is an App made by "); break; case "Add": addUser(); break; case "OK": int userAction1 = JOptionPane.showConfirmDialog(null, "Are You Sure You Want To Insert this Record?"); int number; double number1;
  • 7. boolean emp, ga = false; if(userAction1 == JOptionPane.YES_OPTION) { String firstName = first.getText(); String lastName = last.getText(); String Emplid = emplid.getText(); String Gpa = gpa.getText(); if (firstName.length() < 2) JOptionPane.showMessageDialog(null, "First Name must contain at least 2 characters", null, JOptionPane.ERROR_MESSAGE); else if (lastName.length() < 2) JOptionPane.showMessageDialog(null, "Last Name must contain at least 2 characters", null, JOptionPane.ERROR_MESSAGE); else if (Emplid.length()!=8) JOptionPane.showMessageDialog(null, "EMPLID must contain 8 numbers", null, JOptionPane.ERROR_MESSAGE); try { number = Integer.parseInt(Emplid); try { number1 = Double.parseDouble(Gpa); if(number1 < 0 || number1 > 4) JOptionPane.showMessageDialog(null, "GPA must be between 0.0 - 4.0", null, JOptionPane.ERROR_MESSAGE); else ga = true; } catch (Exception s) { JOptionPane.showMessageDialog(null, "GPA must be between 0.0 - 4.0", null, JOptionPane.ERROR_MESSAGE); } }
  • 8. catch (Exception s) { JOptionPane.showMessageDialog(null, "EMPLID must contain 8 numbers only", null, JOptionPane.ERROR_MESSAGE); } if (ga == true) { model.addRow(new Object[]{rowCount++,firstName, lastName, Emplid, Gpa, Venus}); viewerAdd.setVisible(false); first = new JTextField(20); last = new JTextField(20); emplid = new JTextField(20); gpa = new JTextField(20); venus = new JTextField(10); } } break; case "CANCEL": viewerAdd.setVisible(false); break; } } @Override public void keyTyped(KeyEvent e) { try { venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub string(4,8)); }
  • 9. catch(Exception s) { } Venus = venus.getText(); } @Override public void keyPressed(KeyEvent e) { try { venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub string(4,8)); } catch(Exception s) { } Venus = venus.getText(); } @Override public void keyReleased(KeyEvent e) { try { venus.setText(last.getText().substring(0,2)+first.getText().substring(0,2)+emplid.getText().sub string(4,8)); } catch(Exception s) { } Venus = venus.getText();
  • 10. } } Solution step 1:Go to the Navigation Pane, expand JScrollPane option step 2:In JSCROLLPne, right-click on JTable and Select Customize Code as shown below: step 3:On the code customizer option, choose custom property in the second drop down step 4: Insert the code written below ,before the last bracket);code is given below step5:{public boolean isCellEditable(int row, int column){return false;}}