jscrollpane

How do I get the X and Y location of an image in a JScrollPane

孤街浪徒 提交于 2019-12-01 01:57:31
I am trying to make a Map Editor for a 2D RPG, and what I currently am trying to do (to place tiles on the ground) is to have a JScrollPane with a JLabel (that has an image in it) and a Mouse Listener attached to the JScrollPane to determine the X and Y location of the image. The problem I run into is that it doesn't get the Images X and Y location but the JScrollPanes X and Y location. So I have a JScrollPane attached to an Image that is 512x4928, I attached a mouse listener to it. the problem resides when I try to get the Y location, since JScrollPane is a separate object it gets the X and Y

Add a Jlist to a JScrollPane

折月煮酒 提交于 2019-12-01 01:01:30
I have a JList that I need to Place inside a scroll Pane because I am getting the JList from the database and the values can increase greatly. I need to be able to scroll them down so I wrote: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; public class Checkboxlistener extends JFrame { private JPanel jpAcc = new JPanel(); private JList checkBoxesJList; Checkboxlistener() { //

Swing : JScrollPane doesn't refresh after changes in the structure of a JTable

匆匆过客 提交于 2019-12-01 00:04:05
I have a JTable, associated with a DefaultTableModel, in a JPanel with a SpringLayout which is in a JScrollPane. When I modify the structure of the DefaultTableModel with the method below the JTable is refreshed but not the JScrollPane. I have to apply a second time this method to refresh the JScrollPane. public void updateProjectView() { SwingProjectViewerController spvc = SwingProjectViewerController. getInstance(); this.projectTitle.setText(spvc.getAcronym() + " : " + spvc.getTitle()); Object[][] tableContent = spvc.getCriteria(CriteriaPreselectionController.getInstance().

Scrollbars not appearing in JScrollPane

a 夏天 提交于 2019-11-30 21:27:17
I want to make a window with two buttons with great heights and a scrollbar on a side. The problem is that no scrollbar appears. Here is my code public class Window { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //namestanje teme try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO

How do I get the X and Y location of an image in a JScrollPane

偶尔善良 提交于 2019-11-30 20:37:48
问题 I am trying to make a Map Editor for a 2D RPG, and what I currently am trying to do (to place tiles on the ground) is to have a JScrollPane with a JLabel (that has an image in it) and a Mouse Listener attached to the JScrollPane to determine the X and Y location of the image. The problem I run into is that it doesn't get the Images X and Y location but the JScrollPanes X and Y location. So I have a JScrollPane attached to an Image that is 512x4928, I attached a mouse listener to it. the

How to make JScrollPane scroll 1 line per mouse wheel step?

自作多情 提交于 2019-11-30 20:32:05
I have a JScrollPane whose content pane is a JXList. When I use the mouse wheel on the list, the list steps three (3) items at a time. This also works for a table, regardless of row height. How can I change this so that - regardless of platform - for both list and table the scroll distance is exactly 1 item? Setting block increment doesn't cut it because some rows in the table have a different height. Out of pure interest (and a little boredom) I created a working example: /** * Scrolls exactly one Item a time. Works for JTable and JList. * * @author Lukas Knuth * @version 1.0 */ public class

How to set Focus to the first row in a JTable which is inside a JScrollPane

﹥>﹥吖頭↗ 提交于 2019-11-30 18:46:12
I have a JTable inside a JScrollPane . I have put this inside a panel. As soon the panel loads I want the first row in the JTable to get the focus BUT by default the focus goes to the JScrollPane and on pressing tab the focus enters into table's first row. I dont want to use setRowSelectionInterval(0,0) and setColumnSelectionInterval(0,0) as my requirement is different from that. Luna If you want to edit cell you can use, jTable1.requestFocus(); jTable1.editCellAt(row,column); Or else you want to just select the row, you can use, jTable1.requestFocus(); jTable1.changeSelection(row,column,false

Word wrap in JList items

江枫思渺然 提交于 2019-11-30 18:44:17
I have a JList with very long item names that cause the horizontal scroll-bar to appear in scroll-pane. Is there anyway that I can word wrap so that the whole whole item name appears in 2 rows yet can be selected in one click? I.E it should still behave as a single item but be displayed in two rows. Here is what I did after seeing the example below I added a new class to my project MyCellRenderer and then I went added MyList.setCellRenderer(new MyCellRenderer(80)); in the post creation code of my List. Is there anything else I need to do? Yep, using Andrew's code, I came up with something like

Swing : JScrollPane doesn't refresh after changes in the structure of a JTable

ε祈祈猫儿з 提交于 2019-11-30 18:23:19
问题 I have a JTable, associated with a DefaultTableModel, in a JPanel with a SpringLayout which is in a JScrollPane. When I modify the structure of the DefaultTableModel with the method below the JTable is refreshed but not the JScrollPane. I have to apply a second time this method to refresh the JScrollPane. public void updateProjectView() { SwingProjectViewerController spvc = SwingProjectViewerController. getInstance(); this.projectTitle.setText(spvc.getAcronym() + " : " + spvc.getTitle());

JTable with autoresize, horizontal scrolling and shrinkable first column

拟墨画扇 提交于 2019-11-30 15:02:20
I am having trouble creating a JTable with scrollbars. I want a JTable with 2 columns and no visible scrollbars. If I enlarge one of the columns the scrollbars should become visible and the columns resize. I followed this answer How to make JTable both AutoResize and horizontall scrollable? and works fine which basically comes down to: JTable table = new JTable() { @Override public boolean getScrollableTracksViewportWidth() { return getPreferredSize().width < getParent().getWidth(); } }; table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF ); However, with this solution I cannot shrink the first