How To Add Row Names To JTable

Jan 17, 2015

I'm trying to implement a spreadsheet-like table using JTable and this is the basic structure.

String[] colnames={"A","B","C","D","E"};
String[][]data=new String[28][5];
sheet = new JTable(data,colnames);
//sheet.setBounds(10, 36, 527, 214);
JPanel tablepane=new JPanel();
tablepane.add(new JScrollPane(sheet));
tablepane.setSize(800, 400);

In a spreadsheet, alphabetical letters are column names and numbers represent rows. I have named the columns and I need to name the rows in the same way. Or if I am to set the first column in every row as row headers, how can I make then non-editable by the user? In addition to that, how can I make the table appear bigger? There's a lot of space but the table appears to be small.

View Replies


ADVERTISEMENT

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

Map Same Names In 2 Enums

Oct 2, 2014

I have 2 enums like below

enum enum1{
TEST_1("name_1","name 1"),
TEST_2("name_2,"name 2");

private String name;
private String description;

[Code] .....

How can i map the same names in 2 enums and get message from enum 1 and code from enum 2.

View Replies View Related

Getting Names Of Objects?

Jan 22, 2015

In my project I had to create 2 classes, Room and Animal.

Room had to have an array (NOT arrayList-I know theyre better and easier but I need to use an array, for now) This array must be able to be populated by 10 "Animals", and the Room class needs two methods, a method to add animal a to the room (rooms array) and a toString() that returns the name of the room and the names of the animals in the room. The teacher added a hint saying that this toString() should reference the animal classes toString()

Here is my code thus far:

public class Room {
private String name;
Animal[] inRoom = new Animal[10];
public Room(String roomName){
name = roomName;
} public void addAnimal(Animal a){
for(int i = 0; i < 10; i++){

[code].....

View Replies View Related

How To Compare Two JTable And Set Value From One JTable To Other One

May 26, 2014

I need to compare two jtable and set the value from one jtabel to the other jtable.

jtable one consist of:

Unit ID Unit Name Access

ABC, Inc ABC Incorporate (checkbox) value = uncheck

CDE, Inc CDE Incorporate (Checkbox) value = uncheck

jtable two consist of:

Unit ID Access

ABC, Inc ABC Incorporate (checkbox) value = checked
CDE, Inc CDE Incorporate (Checkbox) value = checked

if comparing jtable one an jtable two has the same Unit ID then colum Access from jtable two value is set to jtable one become check based on jtable two.I did the code but did not work:

for (i = 0, jTable1.getrowcount(), i++) {
for (j = 0, jTable1.getrowcount(), j++) {
if (jTable1.getvalueAt(i,0) == jTable2.getvalueat(j,0)) {
jTable1.setvalueat(true,i,2)
}
}
}

above code i try did not make any changes.

View Replies View Related

Random User Names

Nov 9, 2014

Program is running fine. I can create usernames and everything but somehow I cannot quit or exit the program when I enter my sentinal value "QUIT". Here is my program question: Create an application that will create a username for a school computer system. Input a user’s first and last name. The username will be the first letter of the first name followed by the first 5 letters of his last name followed by a random 3 digit number. Continue to create and display usernames until a sentinel value is entered.

import java.text.*;
import java.util.Random;
import java.text.DecimalFormat;
public class username

[code]...

View Replies View Related

Get All Controls Names On Layout

Oct 1, 2014

I'm new on Java/android and I wounder how could I get name of each control in a layout, ex.

for (int i=0;i<table1.getChildCount();i++ ) {
Object child=table1.getChildAt(i);
if( child instanceof EditText)
{
//get control name here
}
}

View Replies View Related

Randomizing Names From A List?

Feb 2, 2014

I'm trying to use the DataFactory class to pull in a list of names, as I need to populate my app in development with randomized test data for testing.

DataFactory

So, I can get a random name like so:-

package domainentities;
import java.util.Random;
import java.util.Collections;
import org.fluttercode.datafactory.AddressDataValues;

[Code] .....

But - it always prints 'Lindsey'. I need a way of completely randomizing but I can't see the class has a method to let me do this? I can use the randomize method but this takes an int argument which will always bring back the same index value (same name).

I wonder if I am over complicating this. I can use a simple String array of names, but I don't want, like 10,000 names in my array and I want a good way of generating good, randomized data. Perhaps a .csv file of names could be read in? Here is a second method I wrote but I don't have the skills to know how to read the array values from my large .csv file:

public String randomSecondName(){
String[] lastNames = {"Smith", "Jones", "Collins","Jackson",
"Dearsley", "Trump", "Carr", "O'Connell", "Dyer", "Furstzwangler" };
Random ran = new Random();
String lastName = lastNames[ran.nextInt(lastNames.length)];
return lastName;
}

View Replies View Related

Get All Access Table Names?

Jul 12, 2014

I'm using MS Access database. What I want to do, is to get all names of my tables in database.My SQL query :

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES

is it correct? I found it in one example and didn't change anything.

I could of course execute this and check, but the problem is, that it returns ResultSet(I'm using Java), and I do not know how to manipulate this object in this situation.Cause usually ResultSet contains columns and rows, I think now I should get only bunch of String values.

View Replies View Related

How To Sort Names Using Compareto

Feb 24, 2014

i have this problem with my code. it need to put three names in alphabetical order that are entered from the user. then output the alphabetical result. the program compiles but when you put in different names there are not alphabeticals. i think only the first if works good.

import javax.swing.JOptionPane;
public class Sort
{
public static void main(String[] args)
{
String name1;
String name2;
String name3;
 
[code]...

View Replies View Related

How To Separate Names In Scripts

Feb 26, 2014

Java Code:

setseatpos: function(previouspos, position) {
this.seatelement.removeclass("seat-empty").removeclass("seat-pos-" + previouspos).removeclass("seat-inactive").addclass("seat-pos-" + position);
},
renderseat: function() {

[Code] ....

View Replies View Related

How To Make A List Of Names With Java

Oct 16, 2014

One of my assignments was to make a program that would read a sequence of names and then list them all.Just to be clear, it would read them all first, and then it would list them all at the same time.

View Replies View Related

Method Header For File Names?

Feb 27, 2015

I'm new to Methods and do not really know how to write a method header. What would an appropriate header look like for the following instance? getFilename: This method takes no parameters. It asks the user for a filename. If that file exists, it returns the filename. If it does not exist, it asks the user for another filename. It continues to ask for filenames until the user gives the name of a file that exists.

Also, how would I make a return tag for this and call it into the main method.

View Replies View Related

How To Replace Author Names With Numbers

Nov 4, 2014

I have a coauthorship network and I want to replace the authors names with numbers.Part of my datadet:

1992,M_DINE,R_LEIGH,P_HUET,A_LINDE,D_LINDE
1992,C_BURGESS,J_CLINE,M_LUTY
1992,M_DINE,R_LEIGH,P_HUET,A_LINDE,D_LINDE
1992,F_ZWIRNER
1992,O_HERNANDEZ
...

I want the result to be sth like this:

1992 1,2,3,4
1992 5,67
....

and a table of mappings

M_DINE 1
R_LEIGH 2
P_HUET 3

....

I give my dataset in csv (or text) format to my program but it says "(The system cannot find the file specified)" even though the file exists.

what should I do?

here is my code:

Java Code: public class ReadCSV {
HashMap<String, Integer> authorList = new HashMap<>();
File file = new File("d:/Course/thesis/predict/whole.scv");
int authorCounter = 0;
public static void main(String[] args) {
ReadCSV obj = new ReadCSV();

[Code]...

View Replies View Related

Searching Through Array (List Of Names)

Oct 5, 2014

An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?

View Replies View Related

Format Of Java File Names

Mar 30, 2015

In Java® identifiers, you are allowed letters and numbers (also _ $£¢€ etc, but you should avoid them in normal identifiers). So you cannot have spaces. You cannot write public class Hello World because the javac tool will see World as a separate identifier and not understand what it means and will fail to compile the code. You must write public class HelloWorld instead. And because the class is labelled public you must call the source file Hello World. java. Since you can't have two classes with the same [fully‑qualified] name, you cannot write two public classes in the same source file.

“What about names of source files?” somebody will ask. Well, some file systems will permit spaces in file names; ext4 will and I suspect so will NTFS. Can you write file names with spaces in? You would have to have a different name of the class inside the file, because you can't have spaces, and you therefore cannot make the class public, but maybe you can write a package‑private class with a different name.

On ext4, you have to write out the name of the file and the shell will interpret the space as meaning there are two different file, so you have to escape the space.

campbell@campbellsComputer:~/java$ gedit My First Class.java
// My First Class.java
class Foo
{
public static void main(String... args)
{
System.out.println("Hello, World!");
}
}
campbell@campbellsComputer:~/java$ javac My First Class.java
campbell@campbellsComputer:~/java$ java Foo

View Replies View Related

Method Header For File Names?

Feb 26, 2015

I'm new to Methods and do not really know how to write a method header. What would an appropriate header look like for the following instance? getFilename: This method takes no parameters. It asks the user for a filename. If that file exists, it returns the filename. If it does not exist, it asks the user for another filename. It continues to ask for filenames until the user gives the name of a file that exists.

Also, how would I make a return tag for this and call it into the main method.

View Replies View Related

PrintWriter - Ask User For The Names Of Two Files

Jun 30, 2014

Write a program that asks the user for the names of two files. The first file should be opened for reading and the second file should be opened for writing. Ihe program should read the contents of the first file, change all characters to uppercase, and store the results in the second file. The second file will be a copy of the first file, except that all the characters w ill be uppercase. Use Notepad or another text editor to create a simple file that can be used to test the program

Here is my code. I Also made two text document files that are located in the same directory as the .class file (the code file) that are named OriginalFile and UpperCase respectively. Please let me know what I need to do. Here is the code.

import java.util.Scanner;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
public class UpperCaseFile
{
public static void main (String [] args) throws IOException
{

[Code]...

View Replies View Related

Address Book - Unique Object Names

Aug 22, 2014

I found out what my next java class project is, and i am trying to get a head start on it. It is a simple address book. it needs to have 4 choices that get cycled through until quit is chosen:

1. add business contact
2. add personal contact
3. display contacts
4. quit

I have made an abstract contact class with a personal subclass and business subclass(all 3 are required). they have all been made, with set/get methods(the wonders of encapsulation and polymorphism have finally hit home!). The main program needs to add a new subclass object when chosen, and it needs to accept and store contacts by type

So, i am figuring 2 object arraylists for business/personal.

My question is: how do you create an object without having a name for it already programmed? Does it even need to have a unique name, since it would be stored in a seperate index and/or arraylist?

Contact contact = new Contact();
this.firstname = "Be";
this.secondname ="Ginner";
this.phonenumber = "921-456-0102";
personalArray.add (contact);

Then cycle through, changing the properties, and add again to personalArray?

View Replies View Related

Java Program That Keeps Track Of People Names

Jan 13, 2015

I need to make a program that keeps track of peoples names, allows you to add a note to each name and preferably would reorganize whatever you put in by date or by spelling. (I suppose the phonebook application in cell phones is a good match, a supermarket's list of foods and prices would work as well).

View Replies View Related

How To Read Numbers And Names From A Text File

Mar 20, 2014

I have a text file containing numbers and names as shown in the example below:

61133128805241Albert Rosenberg
64763645543509Joel
79256337754219Michael Burton

I'm making a program that will read the file and put the numbers in a list of int arrays and names in another list of strings. In my program i created two classes. One will receive the numbers and the other will receive the names. But i only can read the numbers! How can I read everything and separate into two different lists?

try( BufferedReader br = new BufferedReader( new FileReader( jFileChooser1.getSelectedFile().getAbsolutePath() ) ) ) {
hist = new Historic();//Will recieve the array of numbers.
while( br.ready() ) {
int line[] = new int[ 7 ];

[Code] ...

View Replies View Related

Reverse Grades From Largest To Smallest And Corresponding Names

Jan 20, 2015

I want to reverse grades that i have put using JOptionPane from largest to smallest and the corresponding names..

import javax.swing.*;
import java.util.Arrays;
public class ArrayUtils {
public static void main (String[]args){
String length = JOptionPane.showInputDialog("Number of students");

[code]....

View Replies View Related

Program Ask For Five Names Using Loop Statement And Print All

Jan 24, 2014

write a program that would ask for the five names using loop statement and print all names .

View Replies View Related

How To Write A Program To Record Names And Dates

Mar 2, 2014

I want an app that I can use to save the name, address, item sold, subject discussed and date that I visited someone - in a job similar to a sales rep. I would like to be able to choose how to sort the info so that if I sort by date I can see who hasn't been visited for the longest and start there. If I think of someone's name then of course I want to sort by name.

One of my friends says he works with "php"[? I'm still learning these terms] and everything happens online. I would like it to be an android app so it can be done without an internet connection ....

View Replies View Related

Baby Names Exception In Thread InputMismatchException

Feb 10, 2015

I'm working on an assignment for my java class and I am currently stuck with an error/exception,

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at BabyNames.search(BabyNames.java:45)
at BabyNames.main(BabyNames.java:20)

I input my name, which is able to get my name from the names.txt, however after that, it hits an exception and does not go further on.Also please use the names,

JIMMY
JIMMIE
JIMMU
JIMI
(All can be lowered case), because I am unable to upload the full file for it is very big.

import java.util.*;
import java.awt.*;
import java.io.*;

//Jimmy
//Programming Assignment #6: Baby Names
//This program is going to scan a file with data
//about names and their popularity starting from the 1890's
//and will display their popularity over the years in 10 intervals.

[code]...

View Replies View Related

Print Greetings With Names In Reverse Order And With Punctuation

Apr 10, 2014

Write an application, HiFour that prompt for four names and then prints the greetings, but with the names in reverse order and with punctuation as shown in the example.

Enter four names: Alice Bob Carol Dave

Hi Dave, Carol, Bob, Alice.

View Replies View Related







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