I am writing an application with small fonts in JLabels meant to be displayed on large low res screens.
I create a JLablel using this code, the JFrame has white background.
JLabel myJlabel=new JLabel();
myJlabel.setFont(new Font("Terminal",0,8));
myJlabel.setForeground(Color.black);
myJlabel.setText("Hamburger");
But it looks blurry. The image blow illustrates my problem. On the left it is from a screenshot of my application and on the right it is from the Notapad.exe with the same font and size. One if blurry and on is not.
Here is the images again enlarged and re-screen shot so you won't need to zoom to see my problem.
I need the labels in Java to be just as sharp as on the right. Is there a way to make JLabels not blurry?
I don't know, as you haven't provided any code, but if you have anti-aliasing enabled, that can cause the text to be displayed like it is:
System.setProperty("awt.useSystemAAFontSettings","on");
System.setProperty("swing.aatext", "true");
Try removing these (if they exist), or setting them to "off" and "false" respectively.
Related
I'm looking to write a program that can invert the colors of the entire screen, including the taskbar and everything.
I've tried searching for someone with a similar problem but the results are usually telling me how to change colors in JFrame.
I'm making a minesweeper app in AndroidStudio, and have a layout which I dynamically add the buttons to. I have tried multiple layouts and button types, which have all given me the same problem. I have created 9-patch images for the different background states:
which I set for each button using btn.setBackgroundResource(R.drawable.btn_up).
This all works fine normally, however if the buttons are made too small or there are too many of them, the screen displays strange glitch shapes. The glitch is made worse the larger the number of buttons, and the smaller the size of the buttons. The images below show respectively: small buttons/big grid; slightly bigger buttons; using the red 9-patch as the default background.
This is fixed by using normal png images but I would quite like to use the scalable 9-patch ones. Clicking the buttons changes the glitch shapes, tending to improve the visibility. I have tried simplifying the layout, and I am sure nothing else is affecting it - it is as simple as I've stated. The glitch shapes seem to originate in the top-left corner, and contain the colour of the 9-patch image, as you can see in the screenshots.
Does anyone have any idea why this is happening or how to fix it?
i have an image with a 5px black border what i will use for serveral buttons.
The only problem is, that the buttons have different sizes.
Is there a way to resize it properly?
The only way i can figure it out, is to split it in individually pieces.
Eg.:
The Image is 200x200 and the Button 200x200 -> Border is ok.
The Image is 200x200 (the same) and the button 400x200 -> Border is stretched.
resize an image to diffrerent image ratio without stretch i don't know i someting like taht could exist , but here what i will do to solve your problem
this is your what is happening
to solve this i would use an image border full black and draw it under the image like the picture
when re-size it instead of 400X200 i will decrease it with a little margin like 380x200
hope this was clear and helpfull
After the last Months i´ve learned very much about libgdx and i must say that the use of ninepatches are the best solution.
See here to learn more about 9patch in libGDX
I am working with a java swing application project. I want to make an image as icon in my JPanel but it seems to be low quality image when i am printing the image using the external printer. Here is the code
ImageIcon ii=new ImageIcon(scaleImage(90, 107, ImageIO.read(new File(f.getAbsolutePath()))));
image.setIcon(ii);
How can I make high quality image icon other than this method?
If you use a downscaled version of an image for an Icon, the resolution loss cannot be compensated when printing the icon.
Instead of using ImageIcon, you can create your own icon class (by implementing the javax.swing.Icon interface, it's actually quite simple), which keeps your Image at a higher resolution and paints it at a smaller size (but without quality loss, so you still can see more detail when printing it).
This can be done by applying an AffineTransform/Scale prior to drawing the Image, or by using graphics.drawImage(x,y,width,height,imageObserver).
This is the scenario:
I have one image background set on an activity. On this background, a rectangle has been drawn (in other words, one image depicting a rectangle). I need to display text WITHIN this rectangle.
Right now, I have one solution in mind: since I'm going to optimize the UI for most screens (incl. tablets), I'm going to customize the main .xml layout for each screen size (multiple .xml layouts). Thus, I can manually set the place where the text area goes within the rectangle (+ its size).
I am most certain that this solution is NOT good. I'd like to hear some suggestions from more advanced developers. What would an elegant way of placing text over a background image showing a rectangle, so that the text stays within the rectangle's borders be?
Because I need to set particular positions for other UI elements (centered buttons (vertically/horizontally), I am currently using a Relative Layout.
By default if you have used dp as dimensional measure, your app should in theory work fine for all resoultions. Android by default scales the screen to fit different screens. AndroidDeveloper You just have to make sure that you have different images for resources (Rectangle image). There is another post in SO which you might be intrested to look into link
Cheers
RIchie