JTable Elements Only Show Up When Clicked On Or JFrame Resized
Jan 18, 2015
This is an old project that I had working probably 2 years ago. Since I reopened it the only thing I have changed is the database location. This is a very basic project I did to dip my toes in to Java. I'm going to add it to my portfolio but just to clarify I am not a Java developer so this is mainly there to show that I am not completely blind when it comes to Java.
//Import libraries
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Connection;
import java.sql.DriverManager;
[Code]...
Errors when I click the button that launches the JFrame:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 6 >= 6
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.getValueAt(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
[Code]...
It will launch the window but it will be blank. If I resize the window it will show me the headers. If I click below the headers were the data should be, it will show me the data.
Since it has been so long the only thing I can think of is some of the code has become antiquated. As I said, this was working originally. I just fired it up again to take some screenshots for my portfolio.
View Replies
ADVERTISEMENT
Dec 20, 2014
I am trying to make movingLabel move to a different JPanel each time the JButton is clicked. I can see that the random integer is changing each time the button is clicked, but the movingLabel wasn't doing anything. I noticed that if I click the button and then resize the JFrame with my mouse, it shows in the correct panel. Is there something I am missing, or is there a way to make it automatically display in the correct panel without having to manually resize the JFrame each time? I was thinking that I could add something that resizes the window slightly each time the button is clicked to show it, but I don't think that is probably the "right" way to do it.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class JMovingFrame extends JFrame implements ActionListener
[code]...
View Replies
View Related
Jan 17, 2015
I'm working on an applet for my class. I decided to use AWT even though it's really old.
I'm having trouble with the labels on my program. They don't show up until I click another tab in the browser and then go back to it each time after I click on a button. I tried to use repaint() but it doesn't seem to work. What can I do?
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.color.*;
public class FinalTwo extends Applet implements ActionListener{
Button b1;
Button b2;
[Code]...
View Replies
View Related
Jan 13, 2014
How to add a new JButton in JFrame every time a button is clicked.
In simple words when a button is pressed in JFrame an other button with some specific location is created automatically.
View Replies
View Related
Jan 20, 2015
I'm working on a spreadsheet-like table and I was able to set it so that it would highlight the first cell in the relevant row(titled 1,2,3.. etc) when a cell is clicked. (Just like in MS Excel - preview attached) Now I want to do the same to the column header(i.e. A,B,C,D....etc) . How can I do it?
private void formWindowOpened(java.awt.event.WindowEvent evt) {
setLocationRelativeTo(null);
int rowNum = sheet.getRowCount();
for(int i=0; i<rowNum; i++){
sheet.setValueAt(i+1, i, 0);
[Code] .....
Untitled.jpg
View Replies
View Related
Feb 27, 2014
I'm trying to display the data from database in a jtable by following the jtable demo example in Java Tutorials Sample Code; but, I couldn't output the data to the jtable. The following code is what I've done so far.
import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;
public class Patient { static String szJdbcURL = "jdbc:oracle:thin:@129.78.110.188:1521:MyDB";
static String szUser = "...";
static String szPasswd = "...";
static String szModelName = "...";
[Code] .....
View Replies
View Related
Jan 20, 2014
I want to display a Hash Map to a GUI..my hashmap contains data as follows:
BC111S04=[22, 17302, 50, 17485], BC111S03=[22, 17302, 50, 17485], BC111S02=[22, 17302, 50, 17485], BC111S01=[22, 17302, 50, 17485], BC111SV1=[22, 17302, 50, 17485], BC111SV2=[22, 17302, 50, 17485], BC111M01=[22, 17302, 50, 17485]
in above BCXXXXXX is the Url of DB and the ones in Square bracket are results of some query.I want to display them in format as in below picture:my code for GUI is as follows
package gui;
/**
* Class that takes a query as input from GUI and fetches the required output from Database and display it on GUI.
*/
import java.sql.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import com.POS;
[code]....
View Replies
View Related
Dec 18, 2014
I'm trying to open an image within a JFrame but the image doesn't show. The directory path is correct. The JFrame opens perfectly but no image is showing.
JFrame frame = new JFrame("IMAGE");
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon image = new ImageIcon("images/main.jpg");
JLabel label = new JLabel("", image, JLabel.CENTER);
JPanel panel = new JPanel(new BorderLayout());
panel.add( label, BorderLayout.CENTER );
frame.setVisible(true);
View Replies
View Related
Apr 9, 2014
I have the following project:
Java Code:
package boxmatrics;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class BoxMatrics {
public static void main(String[] args) {
[code]....
Why I have to resize the window(JFrame window) manually, with the mouse, in order to see the components?Where do I need to call repaint(); ?
View Replies
View Related
Jan 19, 2014
I am trying to make a game with an image on it, and I have one class that gets the image and the other is the game. When I run the program, it just shows my image on a gray JFrame. This leads me to think the image might be covering my whole game, which is weird because it is a mostly transparent image. I have tried resizing it and everything but I don't know what to do..
Here is my image class
Java Code:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
public class DisplayImage extends JPanel {
[Code] .....
View Replies
View Related
Jan 31, 2014
i want to make adding into mysql database and then when i click adds, jtable show those data automatically. but it seem to get error at display part, it shows " Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - illegal start of expression" and jtable do not show the added data but in mysql, data is properly kept.
private void jtPropertyChange(java.beans.PropertyChangeEvent evt) {
DefaultTableModel model = (DefaultTableModel) jt.getModel();
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
String sql = "SELECT * FROM `companya`";
[Code].....
the adding part seems to be fine
View Replies
View Related
Jan 31, 2015
There is a Jlist(Jlist1) which is populated with the columnNames from MYSQL. Then There is another empty Jlist (Jlist2) which the user can add items from Jlist1. At this stage I want to know how I can select items of JList2 from MYSQL to show in Jtable. Because the columnnames(items) of Jlist2 is less than the Jlist1. Like Spss that when you select variables from available list then you can add some of variable to selected list and do analysis.
View Replies
View Related
Apr 17, 2014
Pretty much the title. Everything was running fine until a moment, when pain updated only once after the first resize. I've seen some worries about th.start(); or repaint(); but I did not manage to track the problem down since I'm a rookie at programming. Here's the Main class.
import java.applet.*;
import java.awt.*;
public class Main extends Applet implements Runnable
{
// variables
Thread th;
Player player;
static Shot [] shots;
[Code] ....
View Replies
View Related
Feb 23, 2014
I'm trying to create a chess program that uses a JPanel with an 8 by 8 grid layout with 64 jlabels with icons. However, I don't want the icons to be distorted if the user resizes the window in such a way that makes the panel not square. Is there any way I could create a JPanel that maintains a square aspect ratio when it is resized?
View Replies
View Related
Feb 5, 2015
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class array
{
public static void main(String[] args)
[Code] ...
Is there a way to write this, where, alpha is one array.
Write a program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 elements are equal to the square of the index variable and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed.
If I have an array of 50 integers, can I break that to read in lines of 10?
View Replies
View Related
Jan 12, 2015
I am trying to make a 2d array that keeps track of comparison counts. what I have so far works ok but writes over the previous elements with 0. can't seem to find where I am re-initializing the previous elements.
//this is one of my fill sort arrays
public void fillSelectionArray(int index, long countSum) {
//rand = new Random( );
//for ( int i = 0; i < listsize; i++) {
selectionList[ index -1] = countSum;
// }
[Code] ....
I know I am missing something just not sure what.
View Replies
View Related
Apr 30, 2015
I have the following code.
class A {
List<StringBuilder> list;
public void output(List<StringBuilder> objectToOutput){
try(BufferedWriter bw = new BufferedWriter(new FileWriter("temp.txt"))){
for(StringBuilder row:objectToOutput) bw.write(row.toString());
}catch(IOException e){}
[code]....
Why don't the a's show up on the console? I put them in as part of the debugging process and now I don't understand why they don't show up in both places.
View Replies
View Related
Jun 22, 2014
So I have this line of code...
ioexception11.addChoosableFileFilter(new Jframe());
And when I compile it gives me...
error: constructor Jframe in class Jframe cannot be applied to given types;
ioexception11.addChoosableFileFilter(new Jframe());
View Replies
View Related
Apr 2, 2014
Is it possible to go from one method to another when a jbutton is clicked?
View Replies
View Related
May 26, 2015
I have two classes one is called main.java another is called Gui.java
in gui.java, will create a JFrame and some component.here is some code in main.java.
Java Code:
public static void main(String[] args){
while(true)//will always loop once user close the window
Gui gui = new Gui();
gui.setVisible();
if()//at here need to determine button in Gui.java is press or not to process the user input
{
String fromUser = gui.Jusertxt.getText();
}
} mh_sh_highlight_all('java');
what is the code need to use to know Button in Gui.java is clicked or not? i try use method to return true value, but in not working.
View Replies
View Related
Mar 20, 2014
im trying to play a sound when button is clicked. here is the following code
InputStream in;
try {
in = new FileInputStream(new File("failure1.wav"));
AudioStream audios = new AudioStream(in);
AudioPlayer.player.start(audios);
} catch (Exception e) {
}
just wondering why it does load;
i do get the warning
warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioPlayer is internal proprietary API and may be removed in a future release
AudioPlayer.player.start(audios);
View Replies
View Related
Dec 19, 2014
I am using netbeans swing to do my little project . I have one table which is populated by data from a database. I also have another table which should be populated when a user selects a certain row in the first table.Both table have only one column. The logic is when a user selects on row 1,the data in that row should be obtained and should be used to search for certain entities in the database which are returned and used to populate table 2.So after a user selects row1 and decides to select row2 the second table should be updated accordingly. I have attached the java file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package UI;
import java.awt.CardLayout;
import java.sql.SQLException;
import java.util.logging.Level;
[Code] ....
View Replies
View Related
Oct 20, 2014
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.ImageIcon;
[Code] .....
I want the Jbutton Button1 icon to change when i click it howerer i am getting the error can not find symbol for the code in the actionPerformrd method.
View Replies
View Related
Jan 27, 2014
What are a couple of examples to code a button that if it's clicked the panel's visibility is set to false?
View Replies
View Related
Mar 11, 2014
How do i make the 'date' column show only the date and 'timeIn' and 'timeOut' column only show the time. In my database table my 'date' column is a date type and 'timeIn' and 'timeOut' column is time.
View Replies
View Related
Aug 27, 2014
I'm new to java and I'm currently trying to make a program that uses a JTree that implements a properties file. I have the Keys set to the nodes but I want it so that when the node is clicked it will retrieve the keys value from the prop file.
I did have some code for this initially but I as it did not work at the time and was causing issues to my project I got rid of it. I have my code for the jtree,the listener and the prop file.
Tree
Java Code:
JPanel panel_1 = new JPanel();
panel_1.setBackground(Color.WHITE);
panel_1.setSize(new Dimension(22, 0));
scrollPane.setViewportView(panel_1);
Properties properties = new Properties();
[Code] ....
Java Code: add = Adds files changes in your working directory to your index. Example: git add .
rm = Removes files from your index and your working directory so they will not be tracked.
Example: git rm filename mh_sh_highlight_all('java');
Is there a way of doing this? Been trying for a while now but to no prevail. The image is what it currently looks like
View Replies
View Related