My JSlider first value is 0 and the last value is 8850. I want to set the major tick spacing so that the last value (8850) to be printed. For example if I set the major tick spacing to 550 the last value printed will be 8800.
You can use the JSlider#setLabelTable method to control which labels are painted. The JSlider#createStandardLabels avoids that you have to manually create all labels. It is sufficient to use that method to generate them for you, and just add your label for the max value to it.
The Swing slider tutorial even has sample code how to use custom labels
Related
I have a simple grid. Two columns with a variable amount of rows. I want to make it so i have a header row with an arrow that can collapse and show the whole grid. So when I bring up the app, only the header row is visible with an arrow, and I can click to expand/collapse to show the rest of the grid.
A TreeGrid seems like overkill since I don’t need any hierarchical structure, just the ability to collapse/expand one row. I exclusively use IE and I’ve read that Drawyer doesnt work with IE 8 and above. I return a list of the objects and the object just has two string variables.
Any help with this? I am new to Vaadin 8.
Set grid height (workaround)
As a workaround, you could set the height to be approximately the number of pixels you expect to be the height of the header.
See the Sampler demo. Click the gear icon at top to expose properties of the example Grid object. The last property shown is "Size (W x H)". Change 100% to 100px to see the effect.
Grid height set to 100%
Grid height set to 100px
You can also hide the footer (see checkbox in that property list).
I don't think this can be done with plain Vaadin. But I recommend the following simpler approach:
Initially call grid.setHeightByRows(1.5) (javadoc). This will show exactly one row and a half to indicate more data is available. A scrollbar will appear, too.
Make a new column within the grid that has a button or add a button below the grid that - when clicked - calls setHeightByRows with the number of elements in the grid and hides the button. This will show all rows.
Just take a look at this image:
I have 60 entries on the X-axis, the labels of the values do not fit in the small space so they are shown as "...". Is there a way to somehow hide some of these labels in a way that the entire label of the remaining values are shown?
You can override the tick units used by the axis by use the axis' setTickunit() method.
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/NumberAxis.html#setTickUnit-org.jfree.chart.axis.NumberTickUnit-
Linked post: How to use MouseListener to find a specific cell in a grid
I am trying to create a Battleships game, with a 10x10 grid made up of 100 cells. The Grid extends JPanel and the Cell also extends JPanel. Earlier on I made the link above to ask how to implement a MouseListener to do this. As the code is all on that page, I am just going to refer to it.
Someone posted an excellent answer on that link which I accepted. I can now use MouseListener to detect movement, clicks etc in any cell on the grid.
However, I've hit another road block. I am trying to place ships on my grid. I am forgetting about orientation for now (as I'm assuming all ships will be placed horizontally). The first ship will take up five cells. I would like to move my cursor onto a cell on the grid and have four other 'tail' cells, to the right of the cell the cursor is over, highlighted as well. If there aren't five free cells in total (perhaps because the cursor is too near the edge of the grid), the cells will turn red. Otherwise, they will turn green.
After the first ship is placed, the second will need placing. It is four cells long. Therefore, when hovering over a cell it will have a 'tail' of three cells and so on.
I am happy with how to change colours, how to handle orientation and how to change from five ships to four ships and so on. However, I have no idea how to select multiple cells at once.
Does anybody know how to implement this? I would love to post what I have tried but the truth is, I've got nothing.
use JButtons / JToggleButtons instead of JPanels
you can to use Icon (one Image splitted to desired numbers)
by usage of implemented methods in API
use ActionListener for (undecorated) JButton
override ButtonModel for implemented mouse events (without / not required to add MouseListner) in JButton
Generally, selecting a row or column of cells is the same as selecting a rectangle of cells.
The mouseClicked method sets the initial cell.
The mouseMoved method sets the current cell that the mouse is in. This is so you can visually indicate to the user what cells have been "selected".
The mouseReleased method sets the final cell.
You check to see that the initial cell to the final cell makes up a row or a column. The length of the row or column determines which ship you place. This allows you to place the ships in any order, not just largest to smallest.
You'll have to add a MouseMoveListener to use the mouseMoved method.
I'm creating a Swing GUI in Netbeans. The purpose of this GUI is to open an (buffered)image (in a JLabel as icon) and apply Affine transforms on it. Now there are 4 transforms that I'm doing as follows.
Now, each transform requires two sliders to change the X and Y value, except that of rotate, which will require only one. I did it this way since its much better than having to do four tabs for all 4 types of transforms. Also I want it to be such that , for example, if an image is rotated, the same rotated image can be sheared by selecting shear from the Drop down list.
The problem is (are):
How do i repaint the label icon and apply different transform on the same repainted image?
Also, how do i change the minimum and maximum value of JSlider depanding on the effect selected?
You should store originally loaded BufferedImage, and create its copy - that way you won't "destroy" it.
As for the changing value there are methods setMaximum and setMinimum - add listener to list, as stated in Oracle tutorial and modify the values.
As a concrete example of #Daniel's answer, the article Image processing with Java 2D describes the program ImageDicer. It constructs a TreeMap<String, BufferedImageOp> each of which may be selected from a JComboBox and applied to a BufferedImage.
See also related examples here and here.
I'm making an application that has many lines of data coming back from a Database stub(which will become an Oracle database), and for some reason the scroll bar stops at about the 500th element. I'm wondering if there's anyway to have all the elements show within the scroll bar.
I'm assuming here that you're using Windows, because there is a fairly general problem with scrollbars on Windows: the maximum value is a short int, 32,768. Therefore, if the height of the inner composite of a ScrolledComposite is greater than 32,768 pixels, the composite will be clipped.
I haven't found a robust way of fixing this, but there is a workaround: separate the scrollbar from the composite that you wish to scroll. You can't create a ScrollBar, but you can make a ScrolledComposite that is precisely as wide as a ScrollBar, then attach a ScrollListener to it and have it adjust the layout position of the scrolling composite.
Somewhere I have a snippet, but I'm not even exactly sure if this diagnosis applies to your scenario.
You might need to set the minimum and maximum values of the ScrollBar. You would use the setMinimum() and setMaximum() methods, respectively.
It's also a good idea to set the page increment. This is the number of scroll lines that the selected value changes by when the user clicks the area between the thumb and the arrow buttons, or presses the Page Up or Page Down buttons. You would use the setPageIncrement() method.
Finally, Oracle may impose a maximum number of rows you can retrieve from a table. I believe the default is 500 rows.