Material Image Size relative to Button[codenameone] - java

I use FontImage.setMaterialImage(...) or sometimes FontImage.createMaterialImage(...).
How can I ensure the material image size increases or its minimum size is 48x48 px.
Lukman Jaji

I suggest not thinking in pixels but thinking in millimeters as this make far more sense with varying screen sizes.
When you invoke code such as:
FontImage.setMaterialIcon(label, FontImage.MATERIAL_3D_ROTATION);
The image will get the size of the font assigned to the given label. So if the label is styled with a standard medium font (the default) the size will be system specific. To customize this do:
label.setUIID("MyFontUIID");
Then in the designer theme:
Add MyFontUIID
Select the Font tab and select any native font.
Select the size to be in millimeters or pixels to determine a fixed size to the icon. I would recommend millimeters for portability.

Related

Java awt SystemTray - Popmenu too small on Surface 4 Pro

We've a Java application with a trayicon (SystemTray) and a popup menu (PopupMenu) that worked nicely on all platforms.
On a new Surface 4 Pro we've a problem as the size of the menu is amazingly small. Looks as not noticing it's a 'retina'/high definition display.
Is there an easy way to fix this ?
Looks like you may have to resort to setting the menu UI.
See : https://docs.oracle.com/javase/8/docs/api/javax/swing/JPopupMenu.html#setUI-javax.swing.plaf.PopupMenuUI-
Of course that means you need some way to determine that you're running on the Surface Pro in the first place.
You could try figuring out the current font size and dimensions used by the menu UI and compare that with the screen dimensions from Toolkit.getDefaultToolkit().getScreenSize()
As a general solution, which is not tied up to specific devices, you could detect screen resolution in dots-per-inch via:
java.awt.Toolkit.getDefaultToolkit().getScreenResolution()
This will return screen resolution in DPI (dots-per-inch). The bigger this value - the smaller the textual fonts will get for a specific font size.
Use the DPI to set an acceptable (or maximal) DPI settings and calculate the adjustment ratio.
You can adjust either by replacing the UI delegates fonts (for an application-wide effect)
OR, if the issue is specific for the system-tray, by deriving a larger font only for SystemTray's MenuItems:
java.awt.Font defaultFont = java.awt.Font.decode(null); // default font
float adjustmentRatio = 1.0f; // Calculate this based on your metrics
float newFontSize = defaultFont.getSize() * adjustmentRatio ;
java.awt.Font derivedFont = defaultFont.deriveFont(newFontSize);
// PopupMenu with the adjusted font size:
MenuItem item = new MenuItem("Menu Item");
item.setFont(derivedFont);
popupMenu.add(item);

Is there an easy way to tell JSVGComponent to scale SVG image to fit the preferred size?

I tried setting the preferred size, but the SVG image stays the same. Same if I set the size as well. Furthermore, if it does not fit, then nothing is rendered. Batik only has Javadoc and few pages about the architecture.
What I am working on is simple - I have chess pieces as SVG images (100x100 px) and I want to place them inside 8x8 JSVGComponents that dynamically resize to fit the window. I want SVG images to scale to fit the JSVGComponents they are in.

Vaadin relative sizing with component proportions?

I have a GridLayout I'm making which is populated with a bunch of pictures. The GridLayout itself is set to SizeFull(), as is each individual image in the grid.
The grid with the pictures is within another grid, and that grid has relative sizes set.
With this set up, the grid of pictures stays within the spot I want it to, properly resizing to fit within the space they should, but the pictures do not retain their proper square proportions. They squish fat or skinny however they want. I want them to retain the original proportions, though, so they expand to fill their available area as much as possible while retaining those proportions.
If I set the width to 100%, or the height to 100%, and leave the other undefined, then it retains the proportions, and properly expands to fit the one that is set to 100%, but the other spills outside the nested grid layout's spot in the upper grid layout.
Anyone know how to do this?
Have you tried setting the width and height as percentage?
So on an image of 80 by 120 pixels:
setWidth(66, Unit.PERCENTAGE)
setHeight(100, Unit.PERCENTAGE)

TextView dp does not scale with screen size

I am attempting to create a textView that will take up a large portion of the top center part of the screen. Ideally, setting the text size in dp would allow the textView to remain the correct relative size (taking up about 70% of the width of the screen, and maybe 20% of the top). It looks correct in the layout editor, and in the emulator at HVGA resolution. However, when I test it at higher resolutions (on my tablet, or emulating a 720p display) the text takes up a very small portion of the top center part of the screen. (maybe 30% width instead of 70%, and it doesn't seem any larger vertically).
Is there a way to scale text to correctly increase relative size with resolution?
Set the layout_width as fill_parent, which will make it spread across the screen for all devices.
Add some padding on left right and top which seems suitable.
The padding might seem different for different screens but still this might be a better solution.
set
android:layout_width="match_parent"
edit:
check this out
Auto Scale TextView Text to Fit within Bounds

How can I scale my font with different types of screen?

I have made an Android application, but it must work on different types of screen, and I have done that too. But it is 1 thing - for creating scaling screen I use layout_weight and dp instead px. But how can I scale my fonts in .xml files? Thank you.
use android:textSize = "10sp" , sp will scale fonts similar to dp.
You can use sp : scale independent pixels
sp :Scale-independent Pixels - this is like the dp unit, but it is also scaled
by the user's font size preference. It is recommend you use this unit when
specifying font sizes, so they will be adjusted for both the screen density and
the user's preference.

Categories