I created a table with "buttons" aligned onto my screen for my game I am using to learn libgdx. I want the buttons to squeeze together perfectly to form a seamless menu, however there seems to be a natural padding of 1 to 2 pixels between every cell.
Is there a way to remove that padding?
The code seems unnecessary but this is the contents of my table anyways:
table.add(buttonTyce).size(150,60).expandX().expandY().bottom().left().row();
table.add(buttonGrokk).size(150,60).bottom().left().row();
table.add(buttonCeleste).size(150,60).bottom().left().row();
table.add(buttonDaem).size(150,60).bottom().left().row();
table.add(buttonRisp).size(150,60).bottom().left().padBottom(80).row();
table.setFillParent(true);
stage.addActor(table);
Thank you for any help.
I don't think there is default space. Are you sure that the texture you are using for your buttons doesn't contain any transparent edges? Also, there's table.debug() (or something like that, check the docs) to draw lines around table cells for debugging such issues.
Related
I am having a bit of a snag with multi list. I need to fill the multi list with some color. I managed to fill it but still there are some kind of a border that I can't cover. I tried margin 0, padding 0 but the border still exists. I even put a border on the lines and the list, still the same result. I tried putting background for everything. The only choice left is to switch the white borders to black
This looks like it's coming from the MultiButton UIID which you probably won't want to customize. You can workaround this by using:
list.getSelectedButton().setUIID("Container");
list.getUnselectedButton().setUIID("Container");
I suggest avoiding lists entirely as discussed in this post.
Am currently making a game in LibGDX for Android. So far I have a ScrollPane with a table inside that contains a list with custom rows [AS SHOWN IN THE ATTACHED IMAGE]. I want each of those rows surrounded by a rectangle. Is it possible to achieve this?
These are the rows of the list
Since this has been viewed 100 times I might as well contribute even though it's almost 3 years old.
You can set debug on the child widget attached to the Scrollpane (which is probably a Table, so debugAll() or whatever you wish), which outlines the boundaries of the actors automatically.
This internally uses a Shaperenderer to do it from the Stage, and you can change the colour through the Table.debugTableColor, Table.debugCellColor, and Table.debugActorColor static fields.
Table.debugTableColor is for outlining the entire table, Table.debugCellColor is for each of the table's cells, and Table.debugActorColor is for the actors contained within each of the cells.
But yeah, this should only be used for debugging the layout.
I am currently working on a TiledMap editor for a game I am working on. I am now at the part where I need to implement a tile selector. I am pretty sure I would be able to do this in canvas and draw each tile individually and draw a box around the selected tile but I want to know if there is an easier, more professional looking way already implemented in java swing before I start making my own.
Here is a basic drawing of what I want:
Green boxes in tile selector are individual tiles and the one with bold blue it the selected one (Just a basic example, colors don't matter to me).
Additional Info: Each tile has it's own object, so if the solution involves an ArrayList or something, it would work very well. Also I would like to be able to manipulate which objects are shown in the selector or not. I have a search bar that I want to use to narrow down the tiles shown.
Thanks in advance, if you need more details, please ask.
A JList can display a collection of tile images just fine and would be the likely candidate for the tile selector component on the left.
Ok looks pretty good. How do you tell the JList what you want to be displayed about each item in the list. For my case I want to JList to display a simple image, not text, is that possible?
If you add Icons to the JList, they will be automatically displayed correctly. If you need to fine tune the display, then you will want to write a ListCellRenderer as per the tutorials and API.
Also, can it do lists with multiple columns?
If you mean multiple columns of the same thing, such as a 4x4 grid of images, then yes a JList can handle this great, and you would call setLayoutOrientation(JList.HORIZONTAL_WRAP) (or vertical wrap if desired). If you mean columns which each hold a different data type such as an image, text, a checkbox, then go with a JTable.
I have been able to create a grid using an image file (serves as the empty circles), a loop, and GridLayout, but I am well aware that there's more functionality needed (like for dropping the token, though no animation is necessary yet) so I scrapped it and now I'm back to an empty grid. I am stuck and I'm not really sure how I can accomplish this. My code is a mess at the moment so I'm not sure if it'd even make sense for me to post it.
My main problem is how to build a grid, which will then just be filled with a solid color (I'm cancelling using an image file, it seems a little more complicated as far as I'm concerned) with empty circles, that I will be able to fill up with an image file of a token once the player clicks on a button that corresponds to the column he chose (and then reset everything after the game is over). In other words, a rectangle of solid color and with empty circles to be filled up by tokens, but not with solid color, but an image file.
I have been trying to familiarize myself with paint() but I only started learning GUI last week so there are still likely some more things I'll have to learn to probably understand it in a considerable degree.
I am running out of options tantamount to my knowledge of GUI (Swing in particular) and I have been trying to work on this for a week now.
Any hints?
There are multiple possible ways to solve this, but one easy one is to give a JPanel a GridLayout, and then fill it with JLabels with ImageIcons that show empty circles. When the column is selected, the appropriate JLabel is given a new ImageIcon via setIcon that shows a color filled circle.
Also,
Always strive to separate your program logic code from your GUI code, since the better your separation, the easier will be your ability to debug and enhance.
Work on small problems one at a time. Don't move on to the next problem until the current small step is solved.
Work out your logic and ideas on paper first before committing it to code.
Don't "work with paint". If you need to do Swing graphics, you'll want to override a JPanel or JComponent's paintComponent method. The paint method also concerns itself with drawing borders and children, and so overriding it can have nasty and unexpected side effects on these. Also paint is not double buffered by default, and this can lead to bad animation once you start working with animation.
Edit
You state in comment:
Will it be okay to use JButton though? Because that was what i used during my first attempt. I can use setIcon with it too right?
Do you mean use a JButton instead of a JLabel? That would work, and yes you can call setIcon on JButtons, but would make all your rectangles look like buttons. So if that's OK, then do it. Otherwise, you could still use JLabels, and then create a row grid of JButtons to put below or above your game grid, and then have the user press those buttons, and in their ActionListeners have them change the icons of a JLabel in the selected column.
But having said this, I mainly recommend that you use what works best for you. The learning will be in the creating, no matter what you create.
Edit 2
You ask:
do you think it'll be possible/a nice approach to store jlabels in an array and then lay them out in a panel?
Absolutely, either an array of JLabel[] or a List<JLabel> I think is not only possible but in fact essential for this to work well. I think that you're definitely on the right track here.
A customer requested me a software, and one of its requirements is build a form and fill it with data collected from database.
This form is currently being created in Excel. It uses cells to build the form, some cells have blank background, others blank background with black bottom border (to look like a line where text is typed), others have gray background with white text, and there's also a logo image. In Excel, some cells are merged to become bigger than other cells. They fill the text in another spreadsheet and the required cells in the form take that text and format it.
I've looked many report frameworks in Java, some are very complex and some look like Excel's graph builders, but I saw none that can make a complex 2D form like this.
Data filled in it is simple, like name, quantity, some numbers, but they have different length requiring for example that name's cell to be merged to cover a full horizontal line, and some have smaller font size. There's no repeated data that would require sorting and I have no problem gathering the data.
In the end, the filled form must also be printed, so I can't use normal Swing table or grid. It will be used in Windows now, but it'd be nice to support Linux printing too.
Any suggestion of a Java component that builds a 2D layout like this and fills it with strings will be very much appreciated. I even thought of taking a screenshot of their current form and just use 2D Graphics to print the text, but I'd not be able to print it.
This is an example of the kind of form I must build, it's somewhat like that but some areas have gray background with white text:
No, it's not a duplicate, but it is a good example of the layout.