How to style multi list codename one? - java

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.

Related

Java Swing. Add custom items to scroll pane (Tile selector)

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.

Is there always a natural "space" between cells in a table?

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.

Grid building for Connect Four gui

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.

How to determine how far a scrollbar has moved in SWT?

Before Scroll
After Scroll
I am working on creating an Eclipse plugin for tracking of collections (Arrays, Array List, etc.). And I was in need of an SWT Table with expandable columns. In order to implement this, I created several SWT buttons, and generated them before I created the table, and I linked them to the columns that need to be expanded. What I'm having a problem with now is that I need a way to determine how much a user scrolled the scroll bar in order to determine what the new location of the buttons should be. For instance, if the user scrolls 10 pixels to the left, I need to move the buttons 10 pixels to the left, etc.
Is there an easy way to accomplish this within the SWT ScrollBar framework?
Actually, I was able to solve the problem by using Scrollbars "getSelection" method. Turns out, the value that this method represents is the offset from 0 of the scrollbar. In order to solve the problem, I just subtracted the getSelection value from the X position of the buttons

Android - 9 patch

I'm trying to create a new spinner background using a 9 patch picture. I've tried many ways to get a perfect image but I failed :s
Here is my 9 patch:
The content looks to be good when I simulate with Draw-9-patch but the part with the arrow is not displayed, or when it is, this part is totally mal-formed.
I've put the top black line to the whole size and the problem is still the same.
Do you know how to solve it?
Thanks.
Regards.
V.
First of all, you've marked your rounded corners as stretchable, this should be avoided so your corners stay the same, no matter how its stretched.
You've also marked your arrow as being stretchable vertically, which I suppose is not desirable.
See the attached image for a fixed 9-patch (note the differences in 9-patch frame compared to your image), this should scale well in all directions.

Categories

Resources