jscrollpane

How to draw on JPanel on fixed position?

大兔子大兔子 提交于 2019-12-02 05:23:49
I have JPanel wrapped in JScrollPane and I want the rectangle to be drawn always on the same position = moving with scrollbars wont affect the visibility of the rectangle. I tried following code: public void paintComponent(Graphics g) { g.setColor(Color.red); g.drawRect(50, (int)getVisibleRect().getY(), 20 , 20); } but it only repaints the rectangle when size of whole JPanel is changed. IIRC, JScrollPane will try to minimise the amount of redrawing done scrolling, so it wont always cause your component to be updated. The standard technique is to use a JLayeredPane . Add you JScrollPane to a

Java: Can't apply Gridlayout to a Jscrollpane. Get Get java.lang.ClassCastException

倾然丶 夕夏残阳落幕 提交于 2019-12-02 04:48:07
I use a Gridlayout to place 4 elements in one Line. First I had a JPanel and everything worked fine. For the case that the number of lines get to big and I have to be able to scroll down, I changed it a bit. Now I have my JPanel with one JScrollPane added on it. I used the same code, now I just add the elements to the viewport of the Jscrollpane , but now I get this exception Get java.lang.ClassCastException: layout of JScrollPane must be a ScrollPaneLayout: at javax.swing.JScrollPane.setLayout(Unknown Source) and I dont know exactly why. Why shouldnt be Gridlayout's be unknown for Jscrollpane

MigLayout confused by JTable objects contained in JScrollBar objects

烂漫一生 提交于 2019-12-02 04:41:29
问题 It appears the MigLayout becomes confused by JTable objects contained in JScrollPane objects. Since it seems likely that it is a common idiom to have a JTable within a JScrollPane, I thought it would be important to find out why. In the attached example program, a simplified form is created, consisting of 12 rows and 4 columns. All widths and heights are set as percentages. A number of components are added to the form, all by cell position. Some span rows or columns. The last column shows

Add Object to JPanel after button click

放肆的年华 提交于 2019-12-02 04:17:00
I have created a JScrollPane with a JPanel inside it and I want to add JPanel/JLabel/Other objects after pressing the button. For example after three button presses I want to get something like this: I tried myJPane.add(testLabel) with testlabel.setBounds() but no result, I don't want to use GridLayout because of the unchangeable sizes. I would like it if the added objects had different sizes - adjusted to the text content. What should I use for it and how? Thanks in advance. Best regards, Tom. Here is a JPanel inside a JScrollPane that adds JLabel s to it when pressing the button: public

Swing JScrollPane - how to set vertical scroll bar to left?

若如初见. 提交于 2019-12-02 04:11:07
See the title. I've tried to change component orientation to RIGHT_TO_LEFT , but that had a unexpected side effect - it behaves strangely with components with specified preferred size. (JDK 1.6.0_23, Eclipse VE) EDIT Here is the example of this: We have JFrame with jMainScrollPane on it. Inside jMainScrollPane we place a jMainPanel . Now set jMainPanel 's preferred size to be narrower than jMainScrollPane 's. jMainPanel will still take all the space on jMainScrollPane . Now change jMainScrollPane 's orientation to RIGHT_TO_LEFT and see what happen. Sample code (change jMainScrollPane 's

Adding JPanel to JScrollPane

走远了吗. 提交于 2019-12-02 02:55:35
I have a gui which has a Panel that contains a sequence of labels and TextFields and uses a spring layout(this is the mainPanel) and another Panel that just contains a button(buttonPanel). I am trying to make my mainPanel to have a vertical scrollbar as well. I would like to implement my GUI such that within the JFrame I have 2 panels. The mainPanel appears on the top of the frame and the buttonPanel appears below the mainPanel. My problem is I am not able to make the Panels appear such that the buttonPanel is below the mainPanel and I am also not sure how to add a scrollbar to the mainPanel.

Text goes outside JTextArea

試著忘記壹切 提交于 2019-12-02 02:46:54
I am trying to do something in Java which requires me to have a JTextArea in a ScrollPane. Here is how I have defined them: private JTextArea longestparagraph = new JTextArea(); .... JScrollPane scrollpanedreapta = new JScrollPane(longestparagraph, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollpanedreapta.setBorder(BorderFactory.createTitledBorder("Cel mai lung paragraf:")); The problem I'm encountering is that the text doesn't start on a new line when it reaches the right border of the TextArea but it continues. Got any ideas how to solve that? Here's a

Images in JTable cells off by one pixel?

本秂侑毒 提交于 2019-12-02 02:10:47
问题 So, I'm able to load images into my JTable's cells now, but for some reason the graphics are all shifted to the right by one pixel, allowing me to see the JTable's background. Any ideas? Sorry if my formatting's off; still not entirely used to this markup. public static void main(String[] args) { final int rows = 16; final int columns = 16; final int dimTile = 32; JFrame frame = new JFrame("test"); JTable table = new JTable(rows, columns); table.setIntercellSpacing(new Dimension(0, 0)); table

Images in JTable cells off by one pixel?

假装没事ソ 提交于 2019-12-02 01:30:34
So, I'm able to load images into my JTable's cells now, but for some reason the graphics are all shifted to the right by one pixel, allowing me to see the JTable's background. Any ideas? Sorry if my formatting's off; still not entirely used to this markup. public static void main(String[] args) { final int rows = 16; final int columns = 16; final int dimTile = 32; JFrame frame = new JFrame("test"); JTable table = new JTable(rows, columns); table.setIntercellSpacing(new Dimension(0, 0)); table.setShowGrid(false); table.setBackground(Color.cyan); table.setTableHeader(null); table.setRowHeight

ScrollBar movement not smooth in JScrollpane in Swing

僤鯓⒐⒋嵵緔 提交于 2019-12-02 01:18:34
问题 I have a situation like this. I have scrollpane whose viewportView is a JPanel And that JPanel has the layout as BoxLayout. In this panel I add one class which extends JPanel and that class contains JComponents. So while running an application, the JComponents are shown in the JScrollPane. This is how my ScrollPane is formed. The problem here is, When the data exceeds more than around 750 rows, The scrollbar starts giving problems. When scrolling up or down by mouse wheel, scroll doesnot move