Vala error: The name `set_revealed' does not exist in the context of `Gtk.InfoBar' - gtk3

I added a Gtk.InfoBar to my ui and everthing looks OK. In Glade I can switch the Infobar to Revealed and vice versa.
On the valadoc.org Dokumentation set_revealedis listed in the allowed methods.
public void set_revealed (bool revealed)
Sets the GtkInfoBar:revealed property to revealed.
But when I'm building my Project I recive error: The name 'set_revealed' does not exist in the context of'Gtk.InfoBar'
What am I doing wrong?
Here's my code:
namespace Zeiterfassunggtk {
[GtkTemplate (ui = "/org/gnome/Zeiterfassunggtk/window.ui")]
public class Window : Gtk.ApplicationWindow {
[GtkChild]
Gtk.TreeView treeview1 = new Gtk.TreeView ();
[GtkChild]
Gtk.Button refreshbutton;
[GtkChild]
Gtk.MenuButton menubutton;
[GtkChild]
Gtk.Button menubuttonrefresh;
[GtkChild]
Gtk.Button menubuttonsave;
[GtkChild]
Gtk.Button menubuttonquit;
[GtkChild]
Gtk.InfoBar infobar1;
[GtkChild]
Gtk.Label infobar1label;
Gtk.TreeIter iter;
Gtk.ListStore liststore1 = new Gtk.ListStore (3, typeof (string), typeof (string), typeof (string));
private void setup_treeview (Gtk.TreeView treeview1) {
treeview1.set_model (liststore1);
treeview1.insert_column_with_attributes (-1, "Name", new Gtk.CellRendererText (), "text", 0, null);
treeview1.insert_column_with_attributes (-1, "Job", new Gtk.CellRendererText (), "text", 1, null);
treeview1.insert_column_with_attributes (-1, "Time", new Gtk.CellRendererText (), "text", 2, null);
liststore1.append (out iter);
liststore1.set (iter, 0, "Gerald", 1, "Job1", 2, "2018-01-01 18:23", -1);
}
void refresh () {
liststore1.append (out iter);
liststore1.set (iter, 0, "Gerald", 1, "Job1", 2, "2018-01-01 18:23", -1);
//infobar1.set_revealed (true);
}
void save () {
liststore1.append (out iter);
liststore1.set (iter, 0, "Gerald", 1, "Job2", 2, "2018-01-01 24:00", -1);
}
public Window (Gtk.Application app) {
Object (application: app);
this.maximize ();
this.setup_treeview (treeview1);
infobar1.set_revealed (false);
refreshbutton.clicked.connect (this.refresh);
menubuttonrefresh.clicked.connect (this.refresh);
menubuttonsave.clicked.connect (this.save);
menubuttonquit.clicked.connect (app.quit);
this.show_all ();
}
}
}
You can find the full code at github.com

It seems you are importing an older Version of Gtk+. Your window.ui states <requires lib="gtk+" version="3.16"/>.
set_revealed is available from [ Version ( since = "3.22.29" ) ] though.
Seems you'll have to update.
Source#valadoc.org

Related

Update Gtk.Label dynamicall when time changes

I'm using this code to write the current time as a Gtk.Label in an app.
public bool update_time () {
var now = new GLib.DateTime.now_local ();
var settings = new GLib.Settings ("org.gnome.desktop.interface");
var time_format = Granite.DateTime.get_default_time_format (settings.get_enum ("clock-format") == 1, false);
time1_label = new Gtk.Label (now.format (time_format)) {
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER,
margin_top = 5
};
time1_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
time1_label.tooltip_text = time_format;
time1_label.xalign = 0;
return true;
}
The time shows correctly, but I want the label to update to the latest time when it changes. How can I do that?
Maybe use Timeout in some way, but I can't figure out how.
You'll have to create a Timeout, and in its callback change the text of time1_label. (Use Gdk.threads_add_timeout() to add the timeout callback in case any dependencies might be using deprecated GTK locking mechanisms.)
You can use the Timeout as in this example:
public class RefreshLabel : Gtk.Application {
private uint[] timeout_id;
private Gtk.Label label;
public RefreshLabel () {
Object (
application_id: "refreh.my.label",
flags: ApplicationFlags.FLAGS_NONE
);
}
protected override void activate () {
Gtk.ApplicationWindow window = new Gtk.ApplicationWindow (this);
window.set_default_size (100, 50);
window.window_position = Gtk.WindowPosition.CENTER;
window.set_border_width(10);
// create the timeout with your callback that update the label every 1 second
timeout_id += Timeout.add_seconds_full (GLib.Priority.DEFAULT, 1, update_time);
label = new Gtk.Label ("");
var now = new GLib.DateTime.now_local ();
label.set_markup ("<big>" + now.format ("%x %X") + "</big>");
Gtk.Box vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
vbox.pack_start (label, false, false, 0);
window.add (vbox);
window.show_all ();
}
protected override void shutdown () {
// On close all instance of the timeout must be closed
foreach (var id in timeout_id)
GLib.Source.remove (id);
base.shutdown ();
}
public bool update_time () {
var now = new GLib.DateTime.now_local ();
label.set_markup ("<big>" + now.format ("%x %X") + "</big>");
return true;
}
public static int main (string[] args) {
RefreshLabel app = new RefreshLabel ();
return app.run (args);
}
}

Seting TableCell Disable programmatically wierd behaivior

I have a table with quantity and price columns that are editable and not disabled. The table is populated with ObservableList<Collection> . Collection object has a boolean attribute paid. What i am tring to achieve is whenever paid is true, make both price and quantity tablecells disabled and not editable.
This is what i have done so far:
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import javafx.application.Application;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.FloatProperty;
import javafx.beans.property.ReadOnlyFloatProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.converter.FloatStringConverter;
public class CollectionTable extends Application{
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
TableView<Collection> tv = new TableView();
tv.setEditable(true);
TableColumn<Collection, Number> colQty = createQuantityColumn();
colQty.setCellFactory(
new Callback<TableColumn<Collection, Number>, TableCell<Collection, Number>>() {
#Override
public TableCell<Collection, Number> call(TableColumn<Collection, Number> paramTableColumn) {
return new TextFieldTableCell<Collection, Number>() {
#Override
public void updateItem(Number s, boolean b) {
super.updateItem(s, b);
TableRow row = getTableRow();
if (row != null) {
Collection item = (Collection) row.getItem();
//Test for disable condition
if (item != null && item.isPaid()) {
setDisable(true);
setEditable(false);
this.setStyle("-fx-text-fill: grey;-fx-border-color: red");
}
}
}
};
}
});
TableColumn<Collection, Number> colPrice = createPriceColumn();
colPrice.setCellFactory(
new Callback<TableColumn<Collection, Number>, TableCell<Collection, Number>>() {
#Override
public TableCell<Collection, Number> call(TableColumn<Collection, Number> paramTableColumn) {
return new TextFieldTableCell<Collection, Number>() {
#Override
public void updateItem(Number s, boolean b) {
super.updateItem(s, b);
TableRow row = getTableRow();
if (row != null) {
Collection item = (Collection) row.getItem();
//Test for disable condition
if (item != null && !item.isPaid()) {
setDisable(true);
setEditable(false);
this.setStyle("-fx-text-fill: grey;-fx-border-color: red");
}
}
}
};
}
});
TableColumn<Collection, Number> colAmount = createAmountColumn();
TableColumn<Collection, String> colMno = createMNOColumn();
tv.getColumns().addAll(colMno, colQty, colPrice, colAmount);
tv.getItems().addAll(getCollection());
Scene scene = new Scene(new BorderPane(tv), 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
private TableColumn createQuantityColumn() {
TableColumn<Collection, Float> colQty = new TableColumn("Quantity");
colQty.setMinWidth(25);
colQty.setId("colQty");
colQty.setCellFactory(TextFieldTableCell.<Collection, Float>forTableColumn(new FloatStringConverter()));
colQty.setCellValueFactory(cellData -> cellData.getValue().quantityProperty().asObject());
colQty.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<Collection, Float>>() {
#Override
public void handle(TableColumn.CellEditEvent<Collection, Float> t) {
}
});
return colQty;
}
private TableColumn createPriceColumn() {
TableColumn<Collection, Float> colPrice = new TableColumn("Price");
colPrice.setMinWidth(25);
colPrice.setId("colPrice");
colPrice.setCellFactory(TextFieldTableCell.<Collection, Float>forTableColumn(new FloatStringConverter()));
colPrice.setCellValueFactory(cellData -> cellData.getValue().priceProperty().asObject());
colPrice.setOnEditStart(new EventHandler<TableColumn.CellEditEvent<Collection, Float>>() {
#Override
public void handle(TableColumn.CellEditEvent<Collection, Float> t) {
Collection c = ((Collection) t.getTableView().getItems().get(t.getTablePosition().getRow()));
c.setPrice(Math.abs(c.getPrice()));
}
});
colPrice.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<Collection, Float>>() {
#Override
public void handle(TableColumn.CellEditEvent<Collection, Float> t) {
Collection c = ((Collection) t.getTableView().getItems().get(t.getTablePosition().getRow()));
c.setPrice(Math.abs((float)t.getNewValue()));
//int i = collectionHandler.updateCollection(c);
}
});
return colPrice;
}
private TableColumn createAmountColumn() {
TableColumn<Collection, Float> colAmount = new TableColumn("Amount");
colAmount.setMinWidth(25);
colAmount.setId("colAmount");
colAmount.setCellValueFactory(cellData -> cellData.getValue().amountProperty().asObject());
return colAmount;
}
private TableColumn createMNOColumn() {
TableColumn colMNO = new TableColumn("M/NO");
colMNO.setMinWidth(25);
colMNO.setId("colMNO");
colMNO.setCellValueFactory(new PropertyValueFactory("mno"));
return colMNO;
}
private List<Collection> getCollection(){
List<Collection> collections = new ArrayList<>();
collections.add(new Collection(1, 10, "1", false));
collections.add(new Collection(2, 10, "12", true));
collections.add(new Collection(3, 10, "123", true));
collections.add(new Collection(4, 10, "312", true));
collections.add(new Collection(5, 10, "311", false));
collections.add(new Collection(6, 10, "322", true));
collections.add(new Collection(7, 10, "333", true));
collections.add(new Collection(8, 10, "321", false));
collections.add(new Collection(9, 10, "456", true));
collections.add(new Collection(10, 10, "551", true));
collections.add(new Collection(11, 10, "515", false));
collections.add(new Collection(12, 10, "134", true));
collections.add(new Collection(13, 10, "789", true));
collections.add(new Collection(14, 10, "879", false));
collections.add(new Collection(15, 10, "987", true));
collections.add(new Collection(16, 10, "856", true));
collections.add(new Collection(17, 10, "956", true));
collections.add(new Collection(18, 10, "589", true));
collections.add(new Collection(19, 10, "852", false));
collections.add(new Collection(20, 10, "456", false));
collections.add(new Collection(21, 10, "623", true));
collections.add(new Collection(22, 10, "147", false));
collections.add(new Collection(23, 10, "125", true));
collections.add(new Collection(24, 10, "258", false));
collections.add(new Collection(25, 10, "325", true));
collections.add(new Collection(26, 10, "753", true));
collections.add(new Collection(27, 10, "357", false));
collections.add(new Collection(28, 10, "159", false));
return collections;
}
public class Collection{
private final FloatProperty quantity = new SimpleFloatProperty();
private final FloatProperty price = new SimpleFloatProperty();
private final FloatProperty amount = new SimpleFloatProperty();
private final BooleanProperty paid = new SimpleBooleanProperty(false);
private String mno;
public Collection(){
this(0f, 0f, null, false);
}
public Collection(float quantity, float price, String mno, boolean paid) {
setQuantity(quantity);
setPrice(price);
setMno(mno);
setPaid(paid);
this.amount.bind(this.quantity.multiply(this.price));
}
public String getMno() {
return mno;
}
public void setMno(String mno) {
this.mno = mno;
}
public float getQuantity() {
return quantityProperty().get();
}
public void setQuantity(float quantity) {
quantityProperty().set(quantity);
}
public FloatProperty quantityProperty() {
return quantity ;
}
public float getPrice() {
return priceProperty().get();
}
public void setPrice(float price) {
priceProperty().set(price);
}
public FloatProperty priceProperty() {
return price ;
}
public float getAmount() {
return amountProperty().get();
}
public ReadOnlyFloatProperty amountProperty() {
return amount ;
}
public BooleanProperty paidProperty() {
return paid;
}
public void setPaid(boolean approved) {
this.paid.set(approved);
}
public boolean isPaid() {
return paid.get();
}
}
}
The problem with my code is that as i scroll down the table and up again, cells which were previously enabled and editable change to disabled and not editable.
Before scroll After scroll:
The first problem is that you don't reset the state when a cell is reused from one which is paid to one which is not paid. This will happen, among other times, when you scroll. If a cell was previously used in a row that represented a "paid" item (so it is disabled, not editable, and has a red border), and is reused for an "unpaid" item, your updateItem() method will not change the editable or disabled state (or the style). So you should have something like:
if (item != null && item.isPaid()) {
setDisable(true);
setEditable(false);
this.setStyle("-fx-text-fill: grey;-fx-border-color: red");
} else {
setDisable(false);
setEditable(true);
setStyle("");
}
The second problem is that you have no control over the order in which the cell's state is updated. It seems that sometimes the row property is updated after the updateItem() method is called, so you end up with inconsistent state. You can safely use the cell's index to get the correct item from the table's data.
Also note that since both cell factories are identical, there is no need to replicate the code. This works for me:
#Override
public void start(Stage primaryStage) throws Exception {
TableView<Collection> tv = new TableView();
tv.setEditable(true);
TableColumn<Collection, Number> colQty = createQuantityColumn();
Callback<TableColumn<Collection, Number>, TableCell<Collection, Number>> cellFactory = new Callback<TableColumn<Collection, Number>, TableCell<Collection, Number>>() {
#Override
public TableCell<Collection, Number> call(TableColumn<Collection, Number> paramTableColumn) {
return new TextFieldTableCell<Collection, Number>() {
#Override
public void updateItem(Number s, boolean b) {
super.updateItem(s, b);
if (! isEmpty()) {
Collection item = getTableView().getItems().get(getIndex());
// Test for disable condition
if (item != null && item.isPaid()) {
setDisable(true);
setEditable(false);
this.setStyle("-fx-text-fill: grey;-fx-border-color: red");
} else {
setDisable(false);
setEditable(true);
setStyle("");
}
}
}
};
}
};
colQty.setCellFactory(cellFactory);
TableColumn<Collection, Number> colPrice = createPriceColumn();
colPrice.setCellFactory(cellFactory);
TableColumn<Collection, Number> colAmount = createAmountColumn();
TableColumn<Collection, String> colMno = createMNOColumn();
tv.getColumns().addAll(colMno, colQty, colPrice, colAmount);
tv.getItems().addAll(getCollection());
Scene scene = new Scene(new BorderPane(tv), 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
}

Creating static drop down list in Jaspersoft ireport

I'm creating a report in "Jaspersoft iReport designer 5.6.0". What I'm trying to do is add a parameter (a static list that contains values such as: 6 months, 3 months ...). When the user chooses one of these options, I should be able in the Report query, to get the value that the user has chosen, so I can deliver the results upon that selection. I don't want to use jasper server.
Is this possible?
this is my query:
SELECT
DISTRICT."DKEY" AS DISTRICT_DKEY,
DISTRICT."PROVINCE_ID" AS DISTRICT_PROVINCE_ID,
DISTRICT."DISTRICT" AS DISTRICT_DISTRICT
DISTRICT."DURATION" AS DISTRICT_DURATION
FROM
"dbo"."DISTRICT" DISTRICT
where DISTRICT."DKEY" = $P{parameter1}
In iReport you can not create a static list (combobox) of your different month's you can only prompt for the insertion of parameter.
User will need to input manually 3,6 ecc.
<parameter name="parameter1" class="java.lang.Integer" isForPrompting="true">
<defaultValueExpression><![CDATA[3]]></defaultValueExpression>
</parameter>
iReport is not developed to be used by your client, but to be used by you when developing the report.
If you do not wish to use the jasperserver, you can develop your own application for user to select data ecc. Below you find an example of a java swing application, asking to select month and generating preview of the report (you need to fix the connection settings and provide correct path for the jrxml file):
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.util.*;
import javax.swing.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JRViewer;
public class JasperReportInterface extends JFrame {
private static final long serialVersionUID = 5430239481089683268L;
private JComboBox<MonthItem> selectMonts;
public JasperReportInterface() {
super("Jasper Report Interface");
jbInit();
}
private void jbInit() {
this.getContentPane().setLayout(new GridBagLayout());
selectMonts = new JComboBox<MonthItem>();
selectMonts.addItem(new MonthItem(3));
selectMonts.addItem(new MonthItem(6));
this.getContentPane().add(new JLabel("Select month:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 2, 2,
2), 0, 0));
this.getContentPane().add(selectMonts, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2,
2), 0, 0));
JButton btnReport = new JButton("Generate report");
btnReport.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
btnReport_actionPerformed(e);
}
});
this.getContentPane().add(btnReport,new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 2, 2,
2), 0, 0));
}
protected void btnReport_actionPerformed(ActionEvent e) {
String jasperFilePath = "jasper/myJasperFile.jrxml";
Map<String, Object> parameters = new HashMap<String, Object>();
Object v = selectMonts.getSelectedItem();
if (v instanceof MonthItem) {
parameters.put("parameter1", ((MonthItem) v).getMonth());
}
Connection conn = null; // Pass the connection to database or datasource
JasperPrint report;
try {
JasperDesign jasperDesign = JRXmlLoader.load(jasperFilePath);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
report = JasperFillManager.fillReport(jasperReport, parameters, conn);
} catch (JRException e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(this, "Error creating report: " + e1.getMessage());
return;
}
JRViewer jrv = new JRViewer(report);
JDialog viewer = new JDialog(this);
viewer.setTitle("Print preview");
viewer.getContentPane().add(jrv);
viewer.pack();
viewer.setSize(new Dimension(840, 600));
viewer.setLocationRelativeTo(null);
viewer.setVisible(true);
}
class MonthItem {
private int month;
protected MonthItem(int month) {
this.month = month;
}
public String toString() {
return month + " months";
}
public int getMonth() {
return month;
}
}
public static void main(String[] args) {
JasperReportInterface ri = new JasperReportInterface();
ri.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ri.setSize(400,100);
ri.setLocationRelativeTo(null);
ri.setVisible(true);
}
}
Naturally you can also develop a similar web application.

Adding JCheckBox to JTable using Netbeans

I have a JTable in my JDialog which I populate myself in another method. Here is my code and I want the second null in my Object array to be a JCheckBox. I have been scowering the internet and saw someone say I need to override a method in the tablerenderer or something like that and I got confused on how to do it. Anyway here is the code
package privatelessontrackernetbeans;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.TreeMap;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
/**
*
* #author Brent C
*/
public class WeeklyLessonsReductionGUI extends javax.swing.JDialog {
/**
* Creates new form WeeklyLessonsReductionGUI
* #param parent
* #param modal
*/
public WeeklyLessonsReductionGUI(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
postInitComponents();
}
private void postInitComponents() {
ImageIcon icon = new ImageIcon(PSLTrackerInfo.file + "ymcaLogo.png");
setIconImage(icon.getImage());
//Table for students that need more lessons
DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
dtm.setRowCount(0);
//Center the Titles
DefaultTableCellRenderer centerRenderer = (DefaultTableCellRenderer)
jTable1.getTableHeader().getDefaultRenderer();
centerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
//Center the Cells
jTable1.setDefaultRenderer(Object.class, centerRenderer);
TreeMap<Instructor, ArrayList<Student>> theList =
PSLTrackerInfo.theList_getMap();
for (Instructor key : theList.keySet()) {
ArrayList<Student> students = theList.get(key);
boolean listed = false;
for (Student values : students) {
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_MONTH, Calendar.MONDAY);
c.set(Calendar.WEEK_OF_YEAR, values.getLastUpdateWeek());
c.set(Calendar.YEAR, values.getLastUpdateYear());
DateFormat df = new SimpleDateFormat("MMMM dd, yyyy");
Date date = c.getTime();
String s = df.format(date);
if (listed) {
Object[] data = new Object[]{null,
values.getName(), s, null, null, null};
dtm.addRow(data);
} else {
Object[] data = new Object[]{values.getInstructor(),
values.getName(), s, null, null, null};
dtm.addRow(data);
listed = true;
}
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
#SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Lessons Update");
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Instructor", "Student", "Last Update", "Lesson Date", "Lesson Complete", "Unscheduled Lessons"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, false, true, true
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(jTable1);
jButton1.setText("Update");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 829, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(375, 375, 375))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}
No need for a custom renderer, just override the getColumnClass() method of the DefaultTableModel making the column with the boolean a Boolean object.
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
public class CheckBoxTable {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Object[][] data
= {{"false", false},
{"true", true}};
String[] cols = {"String", "Boolean"};
DefaultTableModel model = new DefaultTableModel(data, cols) {
#Override
public Class<?> getColumnClass(int column) {
if (column == 1) {
return Boolean.class;
} else {
return String.class;
}
}
};
JTable table = new JTable(model);
JOptionPane.showMessageDialog(null, new JScrollPane(table));
}
});
}
}
why you just don't do a "new JCheckBox()" instead of the second null??

Connecting to scroll_event in Vala

I've been struggling to connect to the scroll_event of a TextView widget. I can connect a lambda to it, and then run my method, but I'd like to understand why directly connecting doesn't work. I've been using the code below
using Gtk;
public class TextFileViewer : Gtk.Window {
private TextView text_view;
public TextFileViewer () {
this.title = "Text File Viewer";
this.position = WindowPosition.CENTER;
set_default_size (400, 300);
this.text_view = new TextView ();
this.text_view.editable = true;
this.text_view.cursor_visible = true;
var scroll = new ScrolledWindow (null, null);
scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
scroll.add (this.text_view);
this.text_view.scroll_event.connect (on_scroll_event);
var vbox = new VBox (true, 0);
vbox.pack_start (this.text_view, true, true, 0);
add (vbox);
}
private void on_scroll_event () {
stderr.printf("We scrollin breds");
}
public static int main (string[] args) {
Gtk.init (ref args);
var window = new TextFileViewer ();
window.destroy.connect (Gtk.main_quit);
window.show_all ();
Gtk.main ();
return 0;
}
}
That code gives me the error:
gtkviewer.vala:20.46-20.60: error: Argument 1: Cannot convert from `TextFileViewer.on_scroll_event' to `Gtk.Widget.scroll_event'
scroll.scroll_event.connect (on_scroll_event);
vala is at version 0.12.0
Check the scroll-event signal arguments:
public virtual signal bool scroll_event (Gdk.EventScroll event);
private bool on_scroll_event (Gdk.EventScroll e) {
stderr.printf("We scrollin breds");
return true;
}