Swing/AWT/SWT :: Drawings In JPanel Disappears After Scrolling Scrollpane
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();
}
}
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've a swing structure : JPopupMenu contains JPanel which contains JCheckBoxMenuItem. The problem is, I cannot use it because JPopupMenu disappears when mouse enters to any MenuItems.
I added JCheckBoxMenuItem to JPanel(because to make it scrollable, as there are large number of menu-items) and then JPanel to JPopupMenu.
I'm using NetBeans IDE.
Here is the code, done so far.
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PopupTest extends JFrame { JButton button1; public PopupTest() {
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?
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);
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?
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.
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!
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:
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:
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:
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()
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 ?
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.
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 {
I am trying to learn Java and while i was playing a bit with the basic knowledge that i have i encountered a problem. When i run the program, the lines and the picture appear in two separate windows when i compile the program. how can i make them appear in the same? The code is this:
public class Game { private int x; private Picture pic;
try { ByteArrayInputStream in = new ByteArrayInputStream( transferWorker.bOutput .toByteArray()); BufferedImage bufferedImage = ImageIO .read(in);
[Code] ....
But nothing is happening in the GUI. I have stepped through and bufferedimage contains the data, but its not being displayed. Whats happening is, an image is being transmitted to serial port of laptop, so i'm taking it in and storing it in a BufferOutputStream and then trying to open it in my GUI class.
I have a Jframe and i want to add inside 4 different jpanel.This is easy.
what is difficult is how can i change them dynamically with 4 other new jpanels and 4 other new jpanels?
I have try with BorderLayout but not working.
It's a wizard like but not the same.
I have a jpanel with jbuttons jpanel with a jtable jpanel with textarea and jpanel with jlabels. All this have to change with other 4 jpanels, where to look?
How can I make a call to paintComponent within the JPanel-class, from another Class?
In class TestClass:
public class TestClass { public TestClass() { JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.setSize(500,500); initComponents();
I have been trying to create a chat client which makes use of a scrollable jpanel and at runtime adds JTextFields to the panel.
Panel Initialising
msgPanel = new JPanel(new MigLayout()); msgPanel.setPreferredSize(new Dimension(400,335)); JScrollPane msgPanelScroll = new JScrollPane(msgPanel); msgPanelScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); msgPanelScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); mainPanel.add(msgPanelScroll,"span 3,alignx center,wrap");
[Code] .....
But now Im facing the following issues. The text field aligns to the center of the panel & on adding more fields the panel accommodates as it can and does not begin scrolling.
package GUI; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Graphics; import java.awt.Color; public class gui5 { int x=0; int y=0; public static void main(String... x) {
[code]...
but just a Jframe is appearing no Jpanel no green color circle?What is wrong with code
I am try to do an application based in multiples JFrames, each one with its particular responsibilities, and use one JPanel as a menu with buttons that connect one JFrame to another, But this menu is instantiated at run in view (layout made by netbeans) the Main Jframe appears with its internal JPanel, but the instantiated JPanel does not appear or does not show it's buttons. (notice only run method in the second class):
JPanel Menu that will be used in all alone JFrames of application:
public class MenuSuperior extends javax.swing.JPanel { public MenuSuperior() { initComponents(); } private void initComponents() {
Let me explain by simplifying the GUI to a simple frame in which I have a JCheckbox and a JPanel mypanel.mypanel has a Textfield tf,JComboBox cmb as it's components.So now if I deselect the JCheckbox, all the components in the mypanel should be disabled. I used a code like:
but the components inside the panels are not disabled. In my actual program I have a large number of different kinds of components in mypanel.So disabling/enabling each of them on each actionPerformed of the mycheckbox will be laborious. Isn't there any way by which I can disable/enable the mypanel to disable/enable all the components in it?
I trying to replace original (and empty) JPanel in JFrame with my own made one, components does no appear right, when I pass the mouse first button appears:
I need to add 2 JLists inside a JPanel for a crossword. The JPanel is located SOUTH and I'm using BorderLayout in the constructor to locate the JPanel.
The problem is, I can't see the 2 JLists inside the JPanel. For some strange reason the JLists appear in the center where the crosswordPanel is, even though the clues JPanel method is located SOUTH.
I'd like to enable/disable a jpanel and it's entire contents in one fell swoop. I could of course call each component's .setEnabled() method, but I figured there must be a better way!