Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   java (http://www.mac-forums.com/forums/os-x-development-darwin/296820-java.html)

blue sky 03-20-2013 02:07 PM

java
 
I use Mac computers and I have a small java application that works fine on my Mac running Snow Leopard.

When I take this application onto my Macbook Air running Lion the application doesnít render itself the way it does under Snow Leopard.

The problem is with JTabbedPane. It looses the default blue color when a tab is selected or has the focus (under Snow Leopard itís blue under Lion itís gray) and also it is not possible to see which tabs are enabled or disabled under Lion.

I was wondering if someone might have some suggestions of how to fix this JTabbedPane problem.

vansmith 03-20-2013 02:28 PM

What versions of Java are you running on each? Do you have a piece of sample code that we can try?

blue sky 03-20-2013 05:00 PM

java
 
my imac is running snow leopard version: 10.6.8 and my mackbook air i just upgraded to mountain lion version: 10.8.3 and the same problem on mountain lion it won't render JTabbedPane properly.

i am attaching zipped files with code.

vansmith 03-20-2013 05:10 PM

Thanks but I need to know which versions of Java you're running on each machine.

No zip file is available. Can you post a short snippet that demonstrates the tabbed pane issue?

Mod note: I'm going to move this to a more appropriate forum since this is more of a development question.

blue sky 03-20-2013 06:27 PM

java
 
snow leopard is running:

Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-10M4203)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode)

mountain lion is running:

Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-11M4203)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode)

here is the code:

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

public class Grade extends JFrame
{
static JMenu myMenu;
static TabOne tabOne;
static TabTwo tabTwo;
static TabTre tabTre;

static int SW = 800;
static int SH = 550;

static JDesktopPane desk = new JDesktopPane();

static JTabbedPane jtp = new JTabbedPane();
static JMenuBar jmb = new JMenuBar();
static JPanel panel = new JPanel();;

public static void main(String[] args)
{
final Grade f = new Grade();

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

int w = (d.width-SW)/2;
int h = (d.height-SH)/2;
f.setBounds(w, h, SW,SH);

f.setVisible(true);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}

public Grade()
{
super();

this.setTitle("java");

mkGui();

panel.setLayout(new BorderLayout());

setContentPane(desk);
desk.addComponentListener(new ComponentAdapter()
{
public void componentResized(ComponentEvent e)
{
Dimension d = desk.getSize();
panel.setBounds(0,0, d.width, d.height);
panel.validate();
}
});
desk.add(panel);
}

public void mkGui()
{
Thread w = new Thread()
{
public void run()
{
mkMenu();
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
mkTab();
mkTabListener();
}
});
}
};
w.start();
try
{
w.join();
}
catch (InterruptedException e) {}
}

public void mkMenu()
{
JMenuItem myItem = new JMenuItem("Essentials");
myItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});

myMenu = new JMenu("Input");

jmb.add(myMenu);
setJMenuBar(jmb);
}

public void mkTab()
{
jtp.addTab("disable extra", null, tabOne = new TabOne(), "");
jtp.addTab("enable extra", null, tabTwo = new TabTwo(), "");
jtp.addTab("extra", null, tabTre = new TabTre(), "");

jtp.setEnabledAt(2, false);

jtp.setTabPlacement(SwingConstants.TOP);
jtp.setBackground(Color.white);
panel.add(jtp);
}

public void mkTabListener()
{
jtp.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
tabHit();
}
});
}

public void tabHit()
{
if (jtp.getTitleAt(jtp.getSelectedIndex()).equals("di sable extra"))
{
jtp.setEnabledAt(2, false);
}
else
if (jtp.getTitleAt(jtp.getSelectedIndex()).equals("en able extra"))
{
jtp.setEnabledAt(2, true);
}
else
if (jtp.getTitleAt(jtp.getSelectedIndex()).equals("ex tra"))
{
}
}

public class TabOne extends JPanel
{
public TabOne()
{
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add(new JLabel(""), BorderLayout.CENTER);

this.setLayout(new BorderLayout());
this.add(p1, BorderLayout.CENTER);
}
}

public class TabTwo extends JPanel
{
public TabTwo()
{
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add(new JLabel(""), BorderLayout.CENTER);

this.setLayout(new BorderLayout());
this.add(p1, BorderLayout.CENTER);
}
}

public class TabTre extends JPanel
{
public TabTre()
{
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add(new JLabel(""), BorderLayout.CENTER);

this.setLayout(new BorderLayout());
this.add(p1, BorderLayout.CENTER);
}
}
}


All times are GMT -4. The time now is 04:28 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.