Swing/AWT/SWT :: Programmatically Scroll Up Or Down Jtable
Apr 17, 2014
I'm having serious issues right now with a JTable inside a JScrollPane.i have some methods that returns different indexes (rows) that i select programatically in a JTable and the problem is that sometimes it goes beyond of what i can see, like, the row gets selected but the scrollbar won't follow up.
i've searched up in google and saw several different methods but those were extremely complex and for stuff i don't need.the simplest solution i found is this:
tInfo.setRowSelectionInterval(searchIndexes.get(currentIndex), searchIndexes.get(currentIndex));
tInfo.scrollRectToVisible(tInfo.getCellRect(currentIndex, 1, true));
but it just doesn't do anything.My table (tInfo) has only two columns so no horizontal bars, just vertical. What can i do to align the scrollbar with the currently selected row in my table? :C
Found a solution using scrollPane.getVerticalScrollBar().setValue();in another thread, i didn't even notice there were like 3 more threads about the same, just different kind of code used in each.
View Replies
ADVERTISEMENT
Mar 3, 2006
I have a JScrollPane with a JTextArea. The JTextArea is loaded with 10 lines of data. I have two JCheckBox's. The first check box sets the scroll to 10. sp.getVerticalScrollBar().setValue(10); The second check box reloads (ta.setText(text)) the text and then sets the scroll to 10. Why does the second one not work? I have attached a simple program. It is probably easier for you to compile and run than for me to go into detail explaining further.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Tester extends JFrame {
private static final String text = "1
[Code] ......
View Replies
View Related
Sep 30, 2014
I have a java swing application.
1. The human user of my application asks it to fire up a scanner which scans a paper document. The document is a filled in form.
2. The application then displays the scanned image to the human user.The image is displayed in a JScrollPane since it may be larger than the scroll pane.
3. The human user needs to locate a certain item in the form, for example a social security number, and enter it into a field in a data entry screen.Note that the image and the field appear on the same screen.
Of-course the social security number always appears in the same location in the image. Also the image needs to be the appropriate magnification and resolution to allow the human user to easily read and understand the item he is searching for in the image.
What is the best way to present the scanned image to the user such that he immediately sees the item he requires and can enter it into the data entry field.
View Replies
View Related
Sep 6, 2014
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
class Stock extends JFrame implements ActionListener
[code]....
well everything seems to be working fine only the scroll pane is not working.
View Replies
View Related
Sep 5, 2014
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
class Stock extends JFrame implements ActionListener
[Code] ....
Everything is fine but the scroll pane is not working!
View Replies
View Related
Sep 7, 2014
Mouse wheel is working properly on macosx but not working on windows.
Here is my layout structure, i implemented mousewheel listener but its not triggering tho.
And my scrolledcomposite declaration:
final ScrolledComposite scrolledComposite = new ScrolledComposite(mainComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_MAGENTA));
final Composite listComposite = new Composite(scrolledComposite, SWT.NONE);
GridLayout layout = new GridLayout();
[Code] ...
View Replies
View Related
Mar 24, 2015
I am developing application called java compiler... It takes java program as input and compiles and run it, gives output. but if input program has infinite loop then how can identify and stop process execution.
View Replies
View Related
Nov 11, 2014
Why is my create jar file programatically not working? So doing this does create a jar file. When I run the jar file via command line, it gives me "Could not find or load main class ...". I'm not sure exactly why. I took some code i found here: java - How to use JarOutputStream to create a JAR file? - Stack Overflow and apparently it didn't specify the main class so I specifically added it myself. am i doing something wrong? And btw, the file (that contains all the class files) do not have any directories in them. so it's essentially just one folder with a bunch of class files in there. below is the code.
I had the commons-io-2.4 jar referenced into my build path that can be downloaded here: Commons IO - Download Commons IOreason i guess i added to that, though i'm not sure if it was necessary or not, was because it has a file filter which can tell which files are hidden or not and thing is without it it was adding like DS_STORE(which is hidden and i guess unnecessary) to the jar. not sure if this logic is right but just letting you know.
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
[Code]...
View Replies
View Related
Oct 22, 2014
I am looking to reconcile data between SQL server and Oracle DB post the migration, I need to verify the data (rows/columns) for last 10 years, Before i start writing a Java Utility to accomplish this, My question is are there any existing libraries or API which can accomplish the same ....
View Replies
View Related
Dec 9, 2014
I have a stylesheet (mystylesheet.css) with following entry:
.flowpane{
-fx-background-color: rgb(0,0,0);
}
In then start-method of my application I execute:
StackPane root = new FlowPane();
Scene scene = new Scene(root,primaryScreenBounds.getWidth(),primaryScreenBounds.getHeight());
scene.getStylesheets().add(css.getFile());
root.applyCss();
No FlowPane gets black. But if I do that in SceneBuilder and add the stylesheet to root than after loading Fxml-file the FlowPane gets black.
Another approach:
StackPane root = new FlowPane();
Scene scene = new Scene(root,primaryScreenBounds.getWidth(),primaryScreenBounds.getHeight());
scene.getStylesheets().add(css.getFile());
root.getStyleSheets().add(css.getFile());
root.applyCss();
Nothing happens.
StackPane root = new FlowPane();
Scene scene = new Scene(root,primaryScreenBounds.getWidth(),primaryScreenBounds.getHeight());
scene.getStylesheets().add(css.getFile());
root.getStyleSheets().add(css.getFile());
root.getStyleClass().add("flowpanel");
root.applyCss();
Doesn't work too;
but root.setStyle("-fx-background-color: rgb(0,0,0) works. But I need to style my application by css-files.
View Replies
View Related
Nov 5, 2014
I am using servlet 2.4 I used the ff. code below to set httponly in my application's cookies but it did not work. When I do a javascrip alert (document. cooke) in my page, the session id still shows up.
Cookie [] cookies = request.getCookies();
for(int x=0; x<cookies.length; x++){
Cookie cookie = (Cookie) cookies[x];
String cookieValue = cookie.getValue();
cookie.setValue(cookieValue + "; HttpOnly");
}
I also tried doing this and it wouldn't work too
String sessionid = request.getSession().getId();
response.setHeader("SET-COOKIE", "JSESSIONID=" + sessionid + "; HttpOnly");
by the way I am using an application server with its JAVA EE version = 1.4 and JAVA SE version = 5
View Replies
View Related
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
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
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
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
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
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
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
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
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
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
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
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
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
Apr 26, 2015
How can I remove the light blue border? I tried everything that I know [URL]
View Replies
View Related
Mar 18, 2015
I am trying to set the font of the editor as the same for the renderer of JTable. I am just a bit confused on how to do this. I don't want any code but maybe a walkthrough on what to do. Here is my abstract table model ....
public class ProductTableModel extends AbstractTableModel {
private ArrayList <Product> prodList = new ArrayList <Product> ();
private String [] columnNames = {"ID", "Description", "Inventory", "Cost", "Order Quantity"};
public ProductTableModel (ArrayList <Product> productList) {
this.prodList = productList;
[Code] .....
View Replies
View Related