Different behavior when using JOptionPane in Windows7 vs OS X - java

Whenever I run the below code on a Windows 7 machine, I get odd artifacts above one of the buttons.
Typically it's a straight line above whatever button is highlighted by default and as tab over the other buttons I get a straight line above the other buttons as well.
It also looks like I get a line at the very top of the Window. When I've witnessed these same artifacts before in different java UI's I've worked on I've had to do object.setBorder(BorderFactory.createLineBorder(Color.someMatchingColor)). This obviously isn't an option if I'm doing the JOptionPane method.
Is there some known issue with java?
public class TestProj {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JOptionPane.showConfirmDialog(null, "Test");
}
}

Related

Error accessing Cassandra MBeans from Java

I'm trying to access the messaging metrics provided by Cassandra from Java using JMX. I get the correct results when I use the following query with swiss java knife
java -jar sjk-plus-0.4.2.jar mx -s localhost:7100 -mg -all -b org.apache.cassandra.metrics:type=Messaging,name=* -f Mean
org.apache.cassandra.metrics:type=Messaging,name=CrossNodeLatency
1331.0469921040174
org.apache.cassandra.metrics:type=Messaging,name=datacenter1-Latency
1331.1071897694487
However, with the following Java code I get a javax.management.InstanceNotFoundException: org.apache.cassandra.metrics:type=Messaging exception.
JMXServiceURL url = null;
try {
url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:7100/jmxrmi");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JMXConnector mConnector = null;
try {
mConnector = JMXConnectorFactory.connect(url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MBeanServerConnection mMBSC = null;
try {
mMBSC = mConnector.getMBeanServerConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ObjectName mObjectName = null;
try {
mObjectName = new ObjectName("org.apache.cassandra.metrics:type=Messaging");
} catch (MalformedObjectNameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Set<ObjectName> myMbean = null;
try {
myMbean = mMBSC.queryNames(mObjectName, null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
System.out.println((mMBSC.getAttribute(mObjectName, "*")).toString());
} catch (AttributeNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstanceNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MBeanException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ReflectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Could someone please explain where am I making a mistake?
Swiss Java Knife seems to accept an ObjectName wildcard (or pattern) as:
org.apache.cassandra.metrics:type=Messaging,name=*
but your code is simply looking up a non-pattern MBean as:
org.apache.cassandra.metrics:type=Messaging
Change your code to:
Use the pattern
queryNames will return a Set of matching ObjectNames, so iterate through the set and query each one.
You need to specify a string array of actual MBean attribute names, not "*" as in your code. (It would be nice if that was supported)
Something like:
mObjectName = new ObjectName("org.apache.cassandra.metrics:type=Messaging,name=*");
Set<ObjectName> names = mMBSC.queryNames(mObjectName, null);
for(ObjectName on: names) {
System.out.println(on + "\n" + mMBSC.getAttribute(on, "Mean").toString());
}

Any working example for org.netbeans.lib.cvsclient.command.diff.DiffCommand

I want to find out differences between two revisions using org-netbeans-lib-cvsclient-RELEASE712.jar.
any working example?
DiffCommand diffCommand = new DiffCommand();
diffCommand.setRecursive(true);
diffCommand.setRevision1("rel-2230");
diffCommand.setRevision2("rel-2240");
diffCommand.setFiles(new File[]{new File("D:/test/")});
diffCommand.setBuilder(new SimpleDiffBuilder(em, diffCommand));
try {
System.out.println(diffCommand.getCVSCommand());
cvsClient.executeCommand(diffCommand, opts);
Set files = cvsClient.getAllFiles(new File("D:/test/"));
} catch (CommandException | AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Adding components via reflection in swing?

This is probably a very silly way to go about things, but say we had a class with lots of Fields that were components, how would one go about adding them in a for each loop with reflection?
Here is what I've tried so far (though it is obviously doomed to fail):
for(Field bits: this.getClass().getDeclaredFields()){
try {
this.add((Component)Class.forName(bits.getName()).newInstance());
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Each of the fields is not a class so doing the above will not work, but I have defined what they are, and they should exist at runtime.
How should I be doing this?
You try to create a class from a field name, so it won't work.
bits.getName() returns something like "myHelloWorldLabel" and not javax.swing.JLabel.
You can either add the value of the field bits.get(this) or create a new object from the class bits.getDeclaringClass().newInstance().
I would also add a check that the class extends JComponent.

Android - Facebook: an active access token must be used to query information about the current user

i'm using this code:
if(!facebook.isSessionValid()) {
try {
String jsonUser = facebook.request("me");
obj = Util.parseJson(jsonUser);
String id = obj.optString("id");
String name = obj.optString("name");
tv1.setText("sodfnsdf");
} catch (MalformedURLException e) {
tv1.setText("1");
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
tv1.setText("2");
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FacebookError e) {
tv1.setText("3");
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
tv1.setText("4");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
tv1.setText("Error");
}
i've searched online and in stackoverflow, but cannot find the answer to my question, i only found very similiar questions but different in some ways..
Hey you need to call facebook.authorize method
if(!facebook.isSessionValid()) {
facebook.authorize() }
For more information you can refer this link. I think it will help you.
Visit http://www.techrepublic.com/blog/app-builder/integrate-facebook-logins-in-your-android-app/296

When does the TransportEvent get fired in Java mail?

I am trying to get the Message-Id of the sent message by using listeners.
I am implementing
javax.mail.event.TransportListener with concrete methods given in code sample.
It listens to javax.mail.event.TransportEvent which gets generated when void javax.mail.Transport.sendMessage(.....) is called.
To my surprise I get none of the method gets called when I actually send the mail..??? When does it actually get called ? Do I need to add any wait time after calling sendMessage(..)??
Doesn't it happen in real time ?
#Override
public void messageDelivered(TransportEvent e)
{
try {
System.out.println(e.getMessage().getHeader("Message-Id")[0]);
} catch (MessagingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
#Override
public void messageNotDelivered(TransportEvent e)
{
try {
System.out.println(e.getMessage().getHeader("Message-Id")[0]);
} catch (MessagingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
#Override
public void messagePartiallyDelivered(TransportEvent e)
{
try {
System.out.println(e.getMessage().getHeader("Message-Id")[0]);
} catch (MessagingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Did you register your listener with the Transport instance that's being used to send the message? Remember that the static Transport.send() method creates its own Transport instance that you never see.

Categories

Resources