Does anybody know of a Java Look And Feel that renders controls slightly bigger for a more touchscreen friendly application?
9 replies to this topic
#1
Posted 04 April 2011 - 08:40 AM
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
|
|
|
#2
Posted 04 April 2011 - 10:37 AM
In case you don't find a look and feel...
How about just setting the font of all your components to something bigger?
I think most of the components fit to size, so bigger font would hopefully result in bigger components.
Googling for "java change default font" gave me
Change component default font - Real's Java How-to
&
Swing - Changing component default font - Java Forums
That leaves us just with stuff like checkboxes without text, so it also won't resize... Gues you'll have to manually fix that.
Hope it works.
Note: i think the number 50 which I guessed for the dimensions is a bit overguessed, as you can click slightly out of the box and activate it.
How about just setting the font of all your components to something bigger?
I think most of the components fit to size, so bigger font would hopefully result in bigger components.
Googling for "java change default font" gave me
Change component default font - Real's Java How-to
&
Swing - Changing component default font - Java Forums
That leaves us just with stuff like checkboxes without text, so it also won't resize... Gues you'll have to manually fix that.
public class Test extends JFrame {
public Test () {
Font f = new Font("Arial", Font.PLAIN, 50);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, f);
}
}
setLayout(new FlowLayout());
add(new JLabel("label"));
add(new JButton("button"));
add(new JTextField("textfield"));
JCheckBox box = new JCheckBox() {
@Override
protected void paintComponent(Graphics g) {
setPreferredSize(new Dimension(50, 50));
setMinimumSize(new Dimension(50, 50));
setSize(new Dimension(50, 50));
Graphics2D g2 = (Graphics2D) g;
g2.scale(2, 2);
g2.translate(0, -0.5 * getHeight() / 2);
super.paintComponent(g2);
g2.dispose();
}
};
add(box);
setSize(400, 400);
setVisible(true);
}
}
You may want to create separate classes for the non-font stuff.Hope it works.
Note: i think the number 50 which I guessed for the dimensions is a bit overguessed, as you can click slightly out of the box and activate it.
#3
Posted 04 April 2011 - 10:54 AM
That's actually what I've been doing so far, however, I'm also using some Java Bean controls such as JCalendar, and I was hoping there would be a Look and Feel that would simply paint all the buttons bigger, since JCalendar paints it's controls pretty small. I dunno, I was just hoping.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#4
Posted 04 April 2011 - 03:33 PM
You could always write your own Look and Feel for this, depending on whether you know much about underlying GUI code or if you have that time to dedicate to the project. I don't look for other LAF's much.
Wow I changed my sig!
#5
Posted 04 April 2011 - 03:52 PM
I've never written one. I might pursue that, but my boss is pressuring me for results, so I think I'll make it work first, then worry about the look of it. Functionality before beauty. I was just hoping there might already be one out there.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#6
Posted 04 April 2011 - 04:21 PM
I've never used JCalendar but have you tried JCalendar's setPreferredSize( Dimension d ) method?
#7
Posted 04 April 2011 - 04:42 PM
I noticed that JCalendar extends JPanel. if you want every component(buttons, drop down boxes, textfields, etc) in your JCalendar to have a bigger size I'd suggest using the method inherited from Container: getComponents();
You can get every component that JCalendar uses and double/triple/quadruple its size.
If you're adding lots of components, which I assume you are, I'd create my own add method that adds the components to your Jpanel, jframe, whatever.
You can get every component that JCalendar uses and double/triple/quadruple its size.
If you're adding lots of components, which I assume you are, I'd create my own add method that adds the components to your Jpanel, jframe, whatever.
protected void addComponent( JPanel myJPanel, Component c ) {
Dimension d= c.getPreferredSize();
c.setPreferredSize( new Dimension( d.width*2, d.height*2 ));
myJPanel.add(d);
}
protected void addJCalendar(JPanel myJPanel, JCalendar cal) {
Dimension d;
for( Compnent c : cal.getComponents() ) {
d = c.getPreferredSize();
c.setPreferredSize( new Dimension( d.width*2, d.height*2) );
}
myJPanel.add( cal );
}
#8
Posted 04 April 2011 - 05:51 PM
Yeah, that looks like what I'm gonna have to do. Less than elegant, but considering I've gotta get this software written, that method looks like the most practical. Thanks for the tips.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#9
Posted 04 April 2011 - 05:55 PM
Let us know when you find the elegant solution :)
#10
Posted 04 April 2011 - 06:26 PM
Will do. Although it's probably gonna involve me just writing my own look and feel that automatically paints all controls bigger. (I was hoping not to have to change any GUI construction code whatsoever, and have the Look and Feel do all the work. That's what I'd consider the most elegant.) :)
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









