How to center elements in an Android LinearLayout (horizontally)

I was just working on centering some components in an Android LinearLayout and came upon this helpful advice:

android:gravity takes care of its children,
android:layout_gravity takes care of itself

So, in my case, where I wanted to center two buttons horizontally in a LinearLayout, I used android:gravity="center".

How to get the default system font in a Java/Swing application

I haven’t tested this with other Java components, but if you want/need to get the “system font”, this code gets the default system font from a JEditorPane component:

val outputArea = new JEditorPane
val fontFamily = outputArea.getFont.getFamily

That code is written in Scala, but as you can see, it converts easily to Java. On Mac OS X 10.10, fontFamily ends up being “Lucida Grande”.

CakePHP naming conventions

CakePHP naming conventions FAQ: Can you share some examples of the CakePHP naming conventions, specifically the CakePHP model, view, and controller naming conventions?

As I get back into the CakePHP development world, I wanted to make a little CakePHP naming conventions reference page, showing examples of the standard CakePHP naming conventions for CakePHP model, view, and controller elements.

Java UIManager color keys

Java color FAQ: Do you have a list of color keys I can use with the Java UIManager class?


If you're asking this question about the list of color keys in the UIManager class, you probably already know that you can write code like this to use color values from the Java UIManager class:

JFrame size - how to set the JFrame size

Java JFrame FAQ: How do I set the size of a JFrame?

Solution: There are several different ways to set the size of a Java JFrame, but I generally use the setPreferredSize method of the JFrame class in combination with the Java Dimension class, like this:

jframe.setPreferredSize(new Dimension(400, 300));

A JFrame size example

Here's the source code for a complete "JFrame size" example, showing how to use this setPreferredSize method call in an actual Java program.

A Java tooltip tutorial alvin November 10, 2009 - 10:57am

Java Swing FAQ: How do I create a Java tooltip (also known as balloon or bubble help text)?

Is there a package manager for PHP?

PHP FAQ: Is there a package manager for PHP?

Answer: Yes, PEAR (the PHP Extension and Application Repository) is what you need. As the website describes it, "PEAR is a framework and distribution system for reusable PHP components."

Here's an example of how I used PEAR to install the HTTP_Request library, showing both what I typed, and the output from PEAR as it performed the installation.

How to increase the JScrollPane scrolling speed for mousewheel users

Java Swing FAQ: How do I increase the JScrollPane scrolling speed when using the mouse wheel?

Once you put a component (JTextArea, JEditorPane, JTable) into a JScrollPane in a Java Swing application, you'll quickly see that the default scrolling speed when trying to vertically scroll the viewport with the mousewheel is very slow. To make your scroll pane faster, i.e., more like a native Mac or Windows application, you'll want to increase this default mousewheel vertical scrolling speed.