Swing/AWT/SWT :: ScrollPane Not Working As Expected
Mar 11, 2014
I am trying to get a scrollPane working correctly, but not having any luck. The picture drawn in the center panel is quite large and goes off the screen. I visited URL... but I am missing something vital. Both tracks show, but there is no knob to do the scrolling.
public DViewer() {
super();
frame = new JFrame();
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
the problem which im facing when executing jar file is it is not working same as when i run file using the IDE.When run jar file, it won't open the new frame even the user and pass combination correct.But when i'm compiling using the IDE, it works as charm. The main menu popped up after i logged in.I've tried Clean and Build and it's not working too.
I am currently working on a Java project, below are my attempts at coding so far:
public class MyZoo { // zoo identifier private String zooId; // a number used in generating a unique identifier for the next animal to be added to the zoo private int nextAnimalIdNumber; // zstorage for the Animal objects private TreeMap<String, Animal> animals;
[Code] ....
I currently cannot get the printAllAnimals() method to work as it should.
When executing the method printAllAnimals(), it does not do anything, when it is supposed to use the Collection object c, so that animals stored in the zoo can easily be checked.
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(); } }
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.
I'm trying to implement a scene with a ScrollPane in which the user can drag a node around and scale it dynamically. I have the dragging and scaling with the mouse wheel working as well as a reset zoom.
Here's my issue:
I'm having trouble with the calculations to fit the node to the width of the parent. If I zoom in or out, the fit to width does not work. If I change the window size after running fitWidth() once, the fit to width does not work the second time.
Here is my code as an SSCCE and how it works...
1. (works) Mouse wheel will zoom in and out around the mouse pointer 2. (works) Left or right mouse press to drag the rectangle around 3. (works) Left double-click to reset the zoom 4. (doesn't work) Right double-click to fit the width
My calculations to re-position the rectangle to the upper left of the pane and fit it (i.e. scale it up or down) to the width of the parent are incorrect.
I want to create a ScrollPane where I can scale the contents. Think of a simple drawing program that allows you to zoom in and zoom out.
If I create a ScrollPane in SceneBuilder and then drop a couple of Circles into the AnchorPane all looks good.
If I then set a scale of 0.5 for the AnchorPane Scale X and Scale Y the AnchorPane gets scaled about its centre leaving space between the left and top edge of the AnchorPane and the left and top edge of the enclosing ScrollPane.
The only way to get the AnchorPane so that it aligns with the top left of the ScrollPane seems to be to add a negative amount to Translate X and Translate Y.
In my application I would like the user to be able to adjust the zoom (Scale) continually and also the size of the AnchorPane must be allowed to change as the user add/deletes/edits content.
Does this mean I have to continually monitor the AnchorPane properties and set compensating Translate X and Translate Y values each time? Or is there an easier way to achieve what I want?
I am trying to add scrollbars to my frame containing many different components and appearing when user resizes the window with the mouse adds pictures and admin of this online application adds labels or other components.
I want scrollbars to appear when the frame is resized and has components you don't see under so you can scroll down.
If I have for example this code, how i add the scrollbars when i make frame smaller ?
public class Test extends JFrame { private JPanel contentPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() {
I'm trying to get a progress bar to work on my GUI.
This is what I have so far, the parameters are taken from another class that takes in an image in packets from a Raspberry Pi and stores them to a file on PC.
public void ImageInfoReceivedHandler(int sizeOfFile) { progressBar.setMinimum(0); progressBar.setMaximum(sizeOfFile); progressBar.setIndeterminate(false);
[Code] .....
The println are printing out the correct values and they are being implemented in the methods, but nothing is happening in the GUI.
I have a thread setup in the GUI when a button is pressed
getImageButton.setText("Timer Started"); transmit = new transferImage(port); lblImgProcess.setText("Getting Image, Please Wait"); transferThread = new Thread(transmit); transferThread.start();
So the thread starts and image is then transmitted, does the progress bar need to be in that event handler?
after reading the oracle tutorial on how to make frames and reading FrameDemo2.java. URL....i thought setDefaultLookAndFeelDecorated(true); would give me a different decoration than the default windows 7 border.but toggling between true and false changes nothing, and changing setUndecorated does nothing either.what am i supposed to do to make it look like the one in theFrameDemo2 window?
I was suspecting I had a jButton not working, so I added a console print to test. See below. When I click the button, the console doesn't display anything. Am I using the button wrong?
private void jButtonUpdateItemsMouseClicked(java.awt.event.MouseEvent evt) { System.out.println("click"); System.out.println(drawPreviousRectangle);//this is a boolean }
I have also tried the following with the same results (or lack of).
private void jButtonUpdateMajorDeckItemsActionPerformed(java.awt.event.ActionEvent evt) { System.out.println("click"); System.out.println(drawPreviousRectangle);//this is a boolean }
The class does get compiled but the submit button doesn't work?
/** * Orchestration class for Account */ import java.awt.*; //Importing the java.awt.* class import java.awt.event.*;//Importing the java.awt.event.* class import javax.swing.*;//Importing the javax.swing. class public class AccountDemo extends JFrame { /// initializes the variables in the container
I'm trying to make a simple window that displays 5 text fields on x number of rows, depending on what I set x to. Attempting to do this with GridBag Layout but I can't seem to get a new row started. The closest I can get is to repeat the same fields on the same row. I'm trying to modify the row by putting the code in a loop and setting gridy = i, that way each iteration should place the code lower than the first. I'm new with GridBagLayout so I'm probably missing something simple. The constructor with the loop is below. I've commented out code that doesn't seem to work but left the gridx and gridy.
public PAMCalculator() { setTitle("PAM Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(WIDTH, HEIGHT); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints gridConstraints = new GridBagConstraints(); setLayout(gridbag);
I'm trying to make a simple program that will feature some graphics. It will have a JCombobox that the user selects to draw various shapes. I can't get the repaint function to work however.
Whenever I use setLocation(0,0), the JTextArea never moves. It is always in the top middle of the screen, not at (0,0). The same goes for setBounds(0,0,100,100) BUT the height and width are set this way, just not the location. Why is this?
But is not working. I was thinking may be API is not work with java 7 because i got the following warning (AudioStream is internal proprietary API and may be removed in a future release);
I have written a drum machine using Java. Into said drum machine I list all 47 available MIDI drums. The instrument list is placed into a JPanel, along with a gridArray of checkboxes. The JPanel is then in turn added to a scrollpane. I have listed the MIDI drums in order of 'ground-up'. For example, the bass drum is generally at the bottom of most drum kits, so it is at the bottom of my MIDI drums list. Next up would be the snare, followed by the cymbals, and then by all the specialty percussives. Since most beats are started from the 'ground-up', laying to foundation, so to speak, I want the scroll bar of the scrollpane which houses the JPanel, which in turn houses the instrument list and the beat checkboxes, to be positioned, upon opening, at the bottom of the scroll pane. Nothing I have tried works. It always positions the slider somewhere in the middle of the scroll track. Below is a listing of just the buildGUI portion of the code, all the MIDI functionality has been removed to keep the size of the post to this forum down.
When do you get the error <identifier> expected? I've written a small application where input is accepted by a textfield and based on some condition a dialog should be displayed saying "invalid i/p". But am not able to correct ths particular error ....