Here is how you draw a String inside a Java Component based on it’s height and width:
int width, height;
FontMetrics fm = getFontMetrics(ftDefault);
Rectangle2D textsize = fm.getStringBounds(s, g);
int xPos = (width - textsize.getWidth()) / 2;
int yPos = (height - textsize.getHeight()) / 2 + fm.getAscent();
g.drawString(s, xPos, yPos);
I’ve been using JTable on most of my projects and sometimes, there is a need to hide the grid lines. Grid lines are the visible horizontal and vertical lines in a table which clearly display the cells of each row and column. At first, I thought that settings the setShowGrid() property to false will do the trick, but doesn’t really. One property that is needed to be adjusted as well is the setIntercellSpacing(). Here is what you need to set:
table.setIntercellSpacing(new Dimension(0, 0));
Just a while ago I was doing a Java Module, which, based from the mock-up screen, uses a Custom font. I realized that I needed to put this in because many times I might be using this solution, here is goes.
InputStream is = ThisClass.class.getResourceAsStream("/fonts/CaviarDreams.ttf");
Font myfont = Font.createFont(Font.TRUETYPE_FONT, is);
the font that you have loaded has no initial settings on it, so:
myfont = myfont.deriveFont(36.0f);
BTW, I put the TTF Font inside the resources file of my Java Project.
I was into this issue wherein I had to query for some records from the previous 3 months on MySQL. After some searching (I chose to search for existing answers first before using my brain to process such logic :D), here is what I was able to come up with:
select * from attendance where MONTH(attendance_date) >= MONTH(CURDATE()-INTERVAL 3 MONTH);
on the part were I have to state 3 as an interval, you can change it to how many months you would want to cover.
2013 has passed, now its 2014, and what do you know, I wasn’t even able to post a single post here last year. It was such a busy year here at the office. Having been into several company projects (Software Development of course), I was able to improve my coding skills. Much cleaner, and well thought of, unlike during my first years in Java.
Anyways, I decided to keep this blog site alive. So from time to time, I will be posting things like, new things I have learned, some interesting topics I have seen on the web, other off topic discussions not relation to Linux or Software Development, and more.
Ei Guys! Just want to greet you all a Happy New Year. So what’s your New Year’s Resolution? Unfortunately I wasn’t able to fulfill my last year’s, to stay fit. But this 2013, it’s not only about new beginnings, but also continuing what has been started the previous year. So as this year enters, let’s get it on! 😀
Finally, after a few months of development and data gathering, one of our web projects is done. Kindly visit the Home Access Realty for your Home Real Estate and Property needs. You may click here to go to the site now.
It’s been months since my last post, I have been busy with work and at the same time busy with organizing my own company. And now, it’s official, I have established it. I would like to introduce you to Vivace Innovative Solutions, where we do services anything that is related with Information Technology. You may want to visit our website at http://www.vivacesolutions.net. In the near future, well, in a few weeks, I will be integrating this blog site of mine with the Vivace website.
Here is an easy way to select the previous and next entry based on a given ID in MySQL, good for paginations in PHP.
To get the previous entry, query is “SELECT * FROM table_name WHERE id $current_id ORDER BY id ASC LIMIT 1”
You might think it’s easier to use (id – 1) or (id + 1) but it might return errors when id’s are deleted and the count is broken.
Here’s a way to open the jetdirect port on linux, by adding a service wrapper under /etc/xinetd.d/ folder with the name jetdirect. Here is the content:
socket_type = stream
protocol = tcp
wait = no
user = lp
server = /usr/bin/lp
server_args = -d printer1 -o raw
groups = yes
disable = no
Restart the xinetd service and run nmap to see if port 9100 has been opened.