Swing/AWT/SWT :: Tandem Scrolling Of JTables
Jun 14, 2014
I would like to have one horizontal scrollbar control the scrolling of two JScrollPane objects (each of which contains a JTable with similar models). The line of code that I hoped would give me what I want is this:
spUpper.setHorizontalScrollBar(spLower.getHorizontalScrollBar());
It does exactly what I want, except that the scrollbar appears on-screen in the spUpper JScrollPane, while the spLower JScrollPane no longer displays a scrollbar at all. That's the opposite of what I expected. Apparently, spUpper's setHorizontalScrollBar is "stealing" spLower's scrollbar.
An alternative is just to have each scrollbar use the same model, like this:
spUpper.getHorizontalScrollBar().setModel(spLower.getHorizontalScrollBar().getModel());
This links the two scrollbars such that either will control both JScrollPanes (and also the other scrollbar), but it leaves them both visible, which is not what I want. I would have thought this line would make one of them invisible:
spUpper.getHorizontalScrollBar().setVisible(false);
However, it seems to have no effect.
The full code using the first approach is below. My questions are these:
Am I correct that setHorizontalScrollBar not only sets which JScrollBar will control a JScrollPane, but also determines where it appears on the screen?If so, what happens to the original JScrollBar? Is it replaced or am I drawing one on top of the other (or something else)?Why doesn't setVisible(false) make the scrollbar disappear (and how can I do that)?
package tandemtables;
public class Main extends javax.swing.JFrame
{
public Main()
[Code].....
View Replies
ADVERTISEMENT
Mar 1, 2014
I am trying to create a JScrollPane with buttons in it, but I noticed that when I try to scroll, the items all move into ONE row at the top of the JScrollPane. How do I have them vertical? Is there something wrong with the way I am setting up the JScrollPane?
private static void addScrollPane() {
jScrollPane = new JScrollPane(new JPanel());
((JPanel)jScrollPane.getViewport().getView()).add(new JButton("First Button"));
[Code]....
View Replies
View Related
May 24, 2014
I have Implemented a user control / component that allows zooming in and out of a displayed BufferedImage, for discussion's sake, 3rd party libraries are excluded and everything must be from scratch.I have an image rendered on a JPanel, the JPanel is contained within a scrollbar.
Zooming inout etc works perfectly.The Scrollbars are rendered correctly on Zoom In and disappear when I zoom out.I want to add the functionality of focusing on a specific quarter of the displayed image via four dedicated buttons, each send an int (1-4) to a method, that controls the scrollbars.
public void zoomToQuarter(int i)
{
double width = (currentBufferedImage.getWidth()*2.2)+1;
double height = (currentBufferedImage.getHeight()*2.2)+1;
JScrollBar vertical = scrollPane.getVerticalScrollBar();
JScrollBar horizontal = scrollPane.getHorizontalScrollBar();
horizontal.setMaximum((int)width);
vertical.setMaximum((int)height);
[code]....
And resizes the image whilst scrolling the scrollbars accordingly,The method works as expected, and the scrollbars go to the desired location, But there's a catch:The first click on any of the above buttons does not work, but from the second click and on, everything works great!
View Replies
View Related
Oct 31, 2014
I've created a chat program, but now I need to show messages in different colors depending if the message is received or sent. I was wondering if I can use jlabel to do this but in this case I need that jlabels to scroll in a jpanel. how to do this or maybe using a rtf ?
View Replies
View Related
Jan 15, 2014
I am having problems trying to get my jPanel to display my drawings properly after scrolling. (My drawings is done using by overriding the paint() method as the paintComponent() method does not work in my case.) My jPanel is component of my JScrollpane, and my JScrollpane is part of my jFrame.
The organization of components is: JFrame <-- JScrollPane <-- JPanel ( <-- means added to).
Situation: My drawings did appear when the frame becomes start, but when I start scrolling the scrollbar in any direction, it starts to eat up my drawing leaving only part of drawing which is not affected by scrolling.
I want my jpanel to display the drawing properly even after scrolling in both vertical and horizontal directions. I did use revalidate and repaint methods in my method for start of the JFrame.
Some Ways which I have tried:
1) I have tried adding this.revalidate() and this.repaint() method to the paint() method which did retains the image, but the jPanel keeps blinking on my screen which is trying attempt to update the drawing in a recursive manner.
2) I have tried panel.repaint() and panel.revalidate() in my paint() method, but it did not display my drawing.
3) I have read from other sources that I needed a listener to do it, but I am not sure how it works.
// Code Use for Listener
jScrollPane1.getViewport().addChangeListener(new ListenAdditionsScrolled());
public class ListenAdditionsScrolled implements ChangeListener {
public void stateChanged(ChangeEvent e) {
jPanel3.revalidate();
jPanel3.repaint();
}
}
View Replies
View Related
Apr 19, 2014
I have jFrame where I have to display data from database on button click. There are 4 buttons, first to display the first record in database, last to display the last record in database, next to display the next record and previous to display the previous record. I have done first and last record but what should I do to display the next and previous record.
View Replies
View Related
Feb 7, 2014
I have a swing application that gets football scores from a website using Jsoup.
When the "Get Scores" button is pressed, the scores are printed to a JTextArea with a JScrollPane.
I have also used a SwingWorker to update the scores every couple of seconds.
My problem is that every time the JTextArea updates, the JScrollPane scrolls back to the top of the text area. I wan the scroll bar to stay where the user left it.
Here is my code (The update is currently set to update every 1 second so you can see what the scroll bar is like).
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class frame extends JFrame {
[Code] ....
View Replies
View Related
May 20, 2014
My problem is to read a text file which contains lines of text data
{e.g: #1115=CLOSED_SHELL(",(#166,#208,#250.....#1114));}
I need to break it and #numbers in braces are assigned to string array and they should cal by one by one. similarly next level on calling #166 same operation should perform
{#166=ADVANCED_FACE(",(#165),#129,.F.);}
like this 8 levels were there, finally at each level the Calling number should display in JTable.
View Replies
View Related
Oct 9, 2014
I've got a panel which an arbitrary number of text fields may be added to at run time. I've got it set up so that the window's height, and the height of the panel in which the fields appear will never exceed the height of the screen.What I don't have is a way to make the panel scroll to access the fields that are being visually truncated. I'm setting the autoscrolls on the panel to true, but when I run the program, the fields are simply truncated.
pnlDeclensions.setAutoscrolls(true);
View Replies
View Related
Apr 20, 2015
I am making a table that is dynamically made but it isn't working with scroll bars. The scroll bars show but don't work. Here is the code:
JPanel pList = new JPanel();
Component pListl = new JLabel("Here you can view and search for players.");
pList.add(pListl);
tabbedPane.addTab("Player List",pList);
tabbedPane.setMnemonicAt(0,KeyEvent.VK_1);
[Code] ....
Yes I am spamming entries into the result object, this is so I can test the scrolling as right now I don't have enough data for overflowing entries but will do soon.
View Replies
View Related
Nov 1, 2014
i am trying to make a platform game in java and to do this im trying to make a scrolling bacground. i can get the background image to scroll. However, i cant get the image to scroll forever, here is the code.
GamePanel class ( the jpanel )
public class GamePanel extends JPanel implements ActionListener{
static ArrayList<BackGround> store = new ArrayList<BackGround>();
public GamePanel(){
setFocusable(true);
Timer time = new Timer(5,this);
time.start();
store.add(new BackGround(0,-200));
the problem i have is that i want the bacground to loop. however, once the first instance of the background is done scrolling it freezes and doesnt load anymore. here is the code for adding a new background to the list
if(store.get(a).getX() <= -950 ){
GamePanel.store.get(a).setX(-900);
GamePanel.store.add(new BackGround(-951,-200));
}
View Replies
View Related
Mar 31, 2014
There is a problem in my 2D slide scrolling game where the character can't jump until he reaches the enemy.
The Boards class-
package OurGame;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class Board extends JPanel implements ActionListener, Runnable {
[Code] .....
View Replies
View Related
Oct 5, 2014
So I can only get 1 tile to render Okay so now it's no tiles Nvm.
Window
import java.awt.BorderLayout;
import java.awt.HeadlessException;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
[code]....
View Replies
View Related
Apr 6, 2014
I am currently making a platformer game which involves a scrolling panel and a sprite. My intention is for the sprite to be able to jump. My code for the frame that the scrolling panel sits on looks like this:
package Main;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
[Code] ....
Currently I have the sprite (jumpMan) displayed on the JumpPanel. This is where I have a key listener that intends to control the jumping of the sprite by incrementally moving the sprite through the space to simulate jumping slightly more accurately. The JumpPanel is laid on top of a panel called the GamePanel which sits between the main frame and the JumpPanel. I currently have a timer on the main frame which is firing off the action listener every 5ms.
My hope was that the action performed would repaint at intervals so that the you would be able to see the sprite at different stages of the jump and then as it descends as well. However when I try to make the sprite jump nothing happens, nothing changes on the screen - when I debug through I can see the code going into both the keyPressed and actionPerformed methods but this doesn't seem to do anything.
View Replies
View Related
Apr 7, 2015
what I want to be able to do is when the game is over a dialogue box pops up and asks if the user wants to play again and if the user clicks "Yes," then I want to restart the program. I have it to where it recalls my method to play the game which opens the program again, but it doesn't close the old window.
Is there a way to restart the program without the new window popping up? If not, how do I close the old window? Also, how to default the window to being maximized? It makes it easier to see the character and objects on the screen.
View Replies
View Related
Dec 15, 2013
I have datatable with live scrolling enabled.The columns are not getting sorted fully.When one of the columns is sorted,for example "insured" in the image shown below, all the records seem to have sorted but when i reach the end of scroll and next set of records get loaded i see other records in unsorted order as indicated in the image ,when i try to see the column in descending order.So because of this i am not getting the sorting feature accurately done(All records are not getting sorted at a single stretch)
My JSF code snippet
<p:dataTable id="workSpaceList" var="data"
value="#{workSpaceBean.lazylpId}" widgetVar="multiSelection"
selection="#{workSpaceBean.selectedRows}" resizableColumns="true"
liveScroll="true" scrollRows="15" scrollWidth="100%"
scrollHeight="75%" styleClass=".ui-datatable-hor-scroll"
[Code] ....
View Replies
View Related
Feb 7, 2014
I am trying to place a number of JLabel and JTextField objects inside a JPanel which has a JScrollPane.
One thing is, that at one time, I have have a certain number of JLabel and JTextField objects which number would cover an area greater than the JPanel's vertical size.
How when I implement the JScrollPane and I run the program, the scroll bars appear, but they don't scroll the pane inside the JPanel, the items are fixed.
Could the problem be because I am using a Null Layout.
Will I have to use one of the standard layouts available, like GridLayout for the JScrollPane scrolling function to work?
View Replies
View Related
Mar 19, 2015
Okay, gotta be able to move the image when a key is pressed. When I test it, the image moves, but leaves the old image behind.
package Game;
import java.awt.Component;
import javax.swing.JOptionPane;
public class Game
{
private Grid grid; //holds the grid used to store and display images
private int userRow; //keep track of which row the user-controlled image appears in
private int msElapsed; //keep track of the total amount of milliseconds that have elapsed since the start of the game
[Code] ....
Here is what I was given on instructions:
Complete the handleKeyPress method. Write the following line of code in the handleKeyPress method to check for a key press:
int key = grid.checkLastKeyPressed();
If the user pressed the up arrow (key == 38), move the user's image up one row (unless the user is already in the top row). Likewise, if the user pressed the down arrow (key == 40), move the user's image down one row (unless the user is already in the bottom row). Either way, make sure to update userRow.
Movement of the image can be accomplished by changing the value of userRow. Study how the initial image is displayed in the game constructor, then
Set the current image location to null
Update userRow to the new location and,
Set the image in the new value of userRow.
You should be able to move the user image up and down, and you should be prevented from moving the image off the screen.
View Replies
View Related
Feb 21, 2014
I have a primefaces datatable with about 52000 records to be fetched.Since it is a large dataset,i tried using live scrolling feature of primefaces with scroll rows equal to 20.THe number of columns is 53.The table also has filtering and sorting feature on its each column.Still i am not satisfied with the performance of the table.It takes about 15 secs for the page to load,worst thing is that it takes about 65 secs for the next set of 20 records to be loaded on reaching the end of scrolling.
Just for testing i reduced the total number of records to 25000 and the preformance improves with scroll time of 29 secs.I am really not able to understand why it is taking this much time when i am displaying only 20 records at a time.The total number of records should not have affected the performance.
My JSF code snippet
<p:dataTable id="arcRecList" var="data"
value="#{archivedRecordBean.archiveItems}"
tableStyle="table-layout:auto; width:80%;" styleClass="datatable"
scrollable="true" scrollWidth="84%" scrollHeight="69%"
columnClasses="columnwidth" liveScroll="true" scrollRows="20"
filteredValue="#{archivedRecordBean.filteredArchiveItems}">
[Code] ....
View Replies
View Related
Jul 25, 2014
i am developing a web application and uses jsp page to print a payment receipt.
everything works good, but printer scrolls complete sheet after printing first receipt. so need scroll back manually every time i print a receipt.
So, how to stop printer from scrolling entire sheet.
View Replies
View Related
Feb 16, 2014
I have a problem with progress bar implementation to my project. Let me explain it;
I have Jframe named GUI. Filled with 2 datechooser combo box and 1 Buton.
And i have a Swingworker class named "MySwingWorker" for my long running task just like this;
package exampleproject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
[code]....
Just i want add a progress bar for listening MySwingWorker's setProgress updates. When buton clicked swingworker should executed and progress bar should come to screen. I read many articles about that but not understand correctly. Because i am beginner in JAVA.
Question1: Should i (create new class) or (implement to current gui or swingworker class) for progressbar?
Question2: Should i fired progress bar first and execute swingworker from progressbar class? or should i execute swingworker first and fired progress bar later and how?
View Replies
View Related
Jul 26, 2014
Is it a good idea to use the factory design pattern for say if I needed to create four different JDialogs for the same parent frame?
factory design interface
package client;
public interface Dialog {
void getInstanceOf ();
void initComponents ();
}
One of the four JDialog class would look something like this without the comments.
package client;
import javax.swing.JDialog;
@SuppressWarnings("serial")
public class AddCustomerDialog extends JDialog implements Dialog{
public AddCustomerDialog () {
//Some stuff goes here to set the settings for JDialog instance
[code]....
Of course you would have your factory class
View Replies
View Related
Mar 19, 2014
I would like to be able to change the locale in my Swing application at runtime and have all the text elements on the GUI update themselves with localized text from a ResourceBundle of the new locale.If there a simple way of achieving this without having to create an event model for all GUI pages?
View Replies
View Related
Apr 19, 2014
can we create web applications using swings? if yes how to create web app using swing?
View Replies
View Related
Jan 17, 2015
I have created a jtable with two columns so I need add checkboxes dynamically in to the first column.Bıt I couldn find something like add.How can do this.This is what I have so far
public CheckBoxes(){
table=new JTable(new TableModels());
TableColumnModel columnModel = null;
JCheckBox box;
for (int i = 0; i <2; i++) {
[Code] ....
View Replies
View Related
Dec 20, 2014
I've almost finished building an Editor in Java, but i'm a bit stuck on creating a JCheckBox that saves your credentials (as in password only) . I would like it to be on a JPanel under the password input box and above the Login and Register buttons.
Code:
Login.java (Main class for this problem)
[URL] ....
The main thing here is using GridLayout, which is what im currently working with but can't seem to get it under the password input box.. check: [URL] ....
View Replies
View Related